Repository navigation
fix: persist default createdAt so HIT max-age can shrink - #148
Merged
Merged
Conversation
Cache-Control max-age is createdAt + ttl - now. The documented Date.now() default was applied at read time, so every HIT looked freshly generated and browsers/CDNs could keep serving the copy for a full extra TTL.
Hash the payload before the default timestamp so regeneration stays content-based, and run the Date.now TTL case serially so it cannot race sibling tests. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
The documented
createdAtdefault (Date.now()) was applied when serving a cache copy, not when writing it.Cache-Controlmax-age iscreatedAt + ttl - now, so every HIT looked brand new.Trigger: follow the README
getexample (nocreatedAt), request a path, wait, request again. The HIT still advertises the full TTL (reproduced: 3600 after 30s instead of 3570).Impact: browsers and CDNs can keep serving the copy for up to a full extra TTL after the origin entry expires. Default TTL is 24h.
Fix: stamp
createdAtnext toetagwhenget()omits it, so the value is stored with the entry. HITmax-agethen counts down from that timestamp.Validated: new TTL test fails on unpatched code (
max-agestays 3600) and passes with the fix; full suite 35/35.Note
Low Risk
Small behavioral fix to HTTP cache headers when
createdAtis omitted; improves CDN/browser freshness accuracy with no auth or data-path changes.Overview
Fixes cache HIT responses advertising a full TTL when
get()omitscreatedAt.Cache-Controlmax-ageis derived fromcreatedAt + ttl - now, butcreatedAtwas only defaulted at serve time, so each HIT behaved like a fresh entry.The
getwrapper now clones the result, setsetag, and stampscreatedAtat cache write when missing—so stored entries carry the origin time and HITmax-agecounts down correctly.Adds a serial TTL test (mocked
Date.now()) asserting a HIT after 30s reportsmax-age3570 vs 3600 on MISS.Reviewed by Cursor Bugbot for commit 7c03c4d. Bugbot is set up for automated code reviews on this repo. Configure here.