test(cache): verify dev "use cache" parity for cacheMaxMemorySize: 0 and custom handlers (#2110)#2168
Open
Divkix wants to merge 3 commits into
Open
test(cache): verify dev "use cache" parity for cacheMaxMemorySize: 0 and custom handlers (#2110)#2168Divkix wants to merge 3 commits into
Divkix wants to merge 3 commits into
Conversation
…and custom handlers Next.js PR #94784 added a dev-only TieredCacheHandler so that `cacheMaxMemorySize: 0` and slow/remote custom cache handlers no longer surface warm dev reloads as cold cache misses under Cache Components. vinext is immune by design: its dev `"use cache"` path re-executes the function instead of reading the configured handler (the `if (isDev)` short-circuit in cache-runtime.ts), so the handler is never on the dev read path and no front/tiered handler is needed. `"use cache: private"` uses a per-request Map that is never sized from `cacheMaxMemorySize`, so it cannot degrade to a no-op stub either. Lock this deliberate divergence in with regression tests (dev size-0, dev slow custom handler never consulted, dev private under size-0, dev revalidateTag still reaching the handler, and a production parity guard), and document it in cache-runtime.ts and AGENTS.md. No runtime behavior change. Refs: cloudflare#2110, vercel/next.js#94784
commit: |
Contributor
Performance benchmarksCompared 0 improved · 4 regressed · 2 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2110.
Issue #2110 is a
nextjs-trackingparity item asking whether vinext needs Next.js PR #94784's dev-onlyTieredCacheHandler. That PR fixes warmnext devreloads being treated as cold cache misses under Cache Components whencacheMaxMemorySize: 0installs a no-op stub or a custom cache handler'sgetis slow/remote.Finding: vinext is immune by design and needs no
TieredCacheHandler. Next.js's bug is that dev reads the configured cache handler during a staged render, and a read that doesn't resolve in a microtask is counted as a miss. vinext's dev"use cache"path never reads the handler —registerCachedFunctionshort-circuits in dev (packages/vinext/src/shims/cache-runtime.ts, theif (isDev) return executeWithContext(...)branch) and re-executes the function so HMR edits are reflected immediately. Therefore:cacheMaxMemorySize: 0only configures the production/ISRMemoryCacheHandler; it is never on the dev"use cache"read path."use cache", so its latency cannot surface as a cold miss."use cache: private"uses a per-requestMap, never sized fromcacheMaxMemorySize, so it cannot degrade to a no-op stub (the dev-private sub-case Next.js also fixed).Porting
TieredCacheHandleras-is would be inert dead code, so per the repo's "no speculative/dead code" guidance this PR verifies, documents, and locks in the divergence with regression tests. No runtime behavior change.Changes
tests/shims.test.ts— newdev cache paritydescribe block in the"use cache" runtimesuite:cacheMaxMemorySize: 0still returns the real value (no cold miss)get/set"use cache: private"still caches per-request under size-0revalidateTagstill reaches the configured handler under size-0packages/vinext/src/shims/cache-runtime.ts— expand theif (isDev)comment to explain the immunity and reference Dev cache parity: makecacheMaxMemorySize: 0and custom cache handlers fast in dev (TieredCacheHandler) #2110 / Next.js #94784.AGENTS.md— new "Architecture & Gotchas" subsection documenting this deliberate, verified divergence.Testing
Upstream references
cacheMaxMemorySize: 0and custom cache handlers fast in dev vercel/next.js#94784