Skip to content

Commit bd569ac

Browse files
committed
Fix cache by normalizing timestamps and Next.js asset hashes
- Strip ISO timestamps (2025-10-29T16:22:19) before hashing - Normalize Next.js asset hashes in paths (/_next/static/css/abc123...) - Bump CACHE_VERSION to 4 since cache key format changed - This should fix the 99.99% cache miss rate
1 parent cefcb46 commit bd569ac

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

scripts/generate-md-exports.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {unified} from 'unified';
2727
import {remove} from 'unist-util-remove';
2828

2929
const DOCS_ORIGIN = 'https://docs.sentry.io';
30-
const CACHE_VERSION = 3;
30+
const CACHE_VERSION = 4; // Bumped: now normalizing timestamps and Next.js asset hashes
3131
const CACHE_COMPRESS_LEVEL = 4;
3232
const R2_BUCKET = process.env.NEXT_PUBLIC_DEVELOPER_DOCS
3333
? 'sentry-develop-docs'
@@ -259,7 +259,12 @@ async function genMDFromHTML(source, target, {cacheDir, noCache, usedCacheFiles}
259259
const leanHTML = (await readFile(source, {encoding: 'utf8'}))
260260
// Remove all script tags, as they are not needed in markdown
261261
// and they are not stable across builds, causing cache misses
262-
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
262+
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
263+
// Remove ISO timestamps (e.g., "2025-10-29T16:22:19") that change each build
264+
.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?/g, 'BUILD_TIME')
265+
// Normalize Next.js asset hashes in paths (e.g., /_next/static/css/abc123.css)
266+
// so cache isn't invalidated when only asset hashes change
267+
.replace(/\/_next\/static\/([^\/]+)\/[a-f0-9]{16,}/g, '/_next/static/$1/BUILD_HASH');
263268
const cacheKey = `v${CACHE_VERSION}_${md5(leanHTML)}`;
264269
const cacheFile = path.join(cacheDir, cacheKey);
265270
if (!noCache) {

0 commit comments

Comments
 (0)