Skip to content

src, scripts: better directory cache - #1068

Open
flakey5 wants to merge 3 commits into
mainfrom
flakey5/20261024/cache
Open

flakey5 wants to merge 3 commits into
mainfrom
flakey5/20261024/cache

Conversation

@flakey5

@flakey5 flakey5 commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Changes the way the KV directory cache works:

scripts/handle-mainline-release.mjs is triggered by the update links action. Updates the cache entries for the directories that have symlinks. Doesn't add the cache entry for the new released version anymore.

When KV listings are enabled, we try fetching the directory from the KV directory cache like usual. If the directory isn't found however, then we fall back to R2. If R2 has the directory, then we return that result and then cache the R2 result in the KV cache for however long CACHE_KV_TTL is (currently an arbitary 6 hours).

This is 1/2 mrs for this, with the second being a follow up to move us back to using R2's bindings api for uncached directory listings instead of the S3 api.

Fixes #1034

@flakey5
flakey5 requested a review from a team as a code owner October 25, 2026 06:11
Changes the way the KV directory cache works:

`scripts/handle-mainline-release.mjs` is triggered by the update
links action. Updates the cache entries for the directories that have
symlinks. Doesn't add the cache entry for the new released version
anymore.

When KV listings are enabled, we try fetching the directory from the KV
directory cache like usual. If the directory isn't found however, then
we fall back to R2. If R2 has the directory, then we return that result
and then cache the R2 result in the KV cache for however long
`CACHE_KV_TTL` is (currently an arbitary 6 hours).

Fixes #1034

Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
@flakey5
flakey5 force-pushed the flakey5/20261024/cache branch from 1780c66 to 623c576 Compare October 25, 2026 06:16
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Signed-off-by: flakey5 <73616808+flakey5@users.noreply.github.com>
Comment on lines +46 to +70
/**
* Temp helper function for deciding if we wanna use the KV directory cache or
* just R2
*/
function determineDirectoryProvider(path: string, ctx: Context): Provider {
const r2Provider = getR2Provider(ctx);

if (ctx.env.USE_KV) {
if (ctx.env.KV_DIRECTORIES === undefined) {
// Using kv for all directories
return getKvProvider(ctx, r2Provider);
}

for (const prefix of ctx.env.KV_DIRECTORIES) {
if (path.startsWith(prefix)) {
// A path we wanna use kv for
return getKvProvider(ctx, r2Provider);
}
}

// If we're here then it's not a directory we wanna use kv for
}

return r2Provider;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we need to do to make this not temp? Aren't we setting USE_KV already in production?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we setting USE_KV already in production?

Yes but we're still not using it for listing nodejs/release/ + want a way to quickly disable it in case something breaks. Once KV is unconditionally enabled we can just remove this function and call the getKvProvider in listDirectory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v27 nightly releases after 2026-09-07 missing from https://nodejs.org/download/nightly/ directory

2 participants