Repository navigation
fix: treat maxAge 0 as "do not cache" - #263
Open
derrickmehaffy wants to merge 1 commit into
Open
derrickmehaffy wants to merge 1 commit into
derrickmehaffy wants to merge 1 commit into
Conversation
keyv and cache-manager read a ttl of 0 as "no expiry", so a route configured with maxAge 0 was stored forever - while, with cacheControl enabled, the response itself told clients max-age=0. A maxAge of 0 or less now stores nothing: recv returns the response without writing an entry or an ETag, and cacheStore.set refuses such a lifetime for any caller. Positive maxAge values are unchanged.
This branch has not been deployed
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.
What changed and why
maxAge: 0cached a route forever:0as "no expiry", and the value was passed straight through;cacheControlenabled, the same response told clientsmax-age=0, while the server kept serving it from the cache indefinitely;Decision (maintainer):
maxAge: 0means do not cache.Fix:
recv.ts: a route whose resolvedmaxAgeis<= 0returns its response without writing an entry or an ETag. An ETag would be useless anyway, because the server could never revalidate it.cacheStore.setrefuses a lifetime<= 0for any caller, including application code, rather than store it forever.maxAgevalues are unchanged.Behaviour change: only for configurations that set
maxAge: 0. They move from cached-forever, which contradicted their ownCache-Control, to not cached, as decided. Documented indocs/guide/caching/index.md.Tests
New
shared/tests/max-age-zero.test.js, using the existingCATEGORY_MAX_AGEfixture switch:mainmaxAge: 0route is aMISSon the second requestHIT)cacheStore.set(key, val, 0)stores nothingThe full memory suite passes 252/252, and
test:lintis green.Checklist
pnpm run test:e2e:memorypasses.pnpm run test:lintpasses.docs/guide/updated.main.