Skip to content

fix: persist default createdAt so HIT max-age can shrink - #148

Merged
Kikobeats merged 2 commits into
masterfrom
cursor/critical-bug-management-c688
Sep 10, 2026
Merged

Kikobeats merged 2 commits into
masterfrom
cursor/critical-bug-management-c688

Conversation

@cursor

@cursor cursor Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

The documented createdAt default (Date.now()) was applied when serving a cache copy, not when writing it. Cache-Control max-age is createdAt + ttl - now, so every HIT looked brand new.

Trigger: follow the README get example (no createdAt), 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 createdAt next to etag when get() omits it, so the value is stored with the entry. HIT max-age then counts down from that timestamp.

Validated: new TTL test fails on unpatched code (max-age stays 3600) and passes with the fix; full suite 35/35.

Open in Web View Automation 

Note

Low Risk
Small behavioral fix to HTTP cache headers when createdAt is omitted; improves CDN/browser freshness accuracy with no auth or data-path changes.

Overview
Fixes cache HIT responses advertising a full TTL when get() omits createdAt. Cache-Control max-age is derived from createdAt + ttl - now, but createdAt was only defaulted at serve time, so each HIT behaved like a fresh entry.

The get wrapper now clones the result, sets etag, and stamps createdAt at cache write when missing—so stored entries carry the origin time and HIT max-age counts down correctly.

Adds a serial TTL test (mocked Date.now()) asserting a HIT after 30s reports max-age 3570 vs 3600 on MISS.

Reviewed by Cursor Bugbot for commit 7c03c4d. Bugbot is set up for automated code reviews on this repo. Configure here.

cursoragent and others added 2 commits September 10, 2026 04:07
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>
@Kikobeats
Kikobeats marked this pull request as ready for review September 10, 2026 11:02
@Kikobeats
Kikobeats merged commit a70f4a3 into master Sep 10, 2026
3 checks passed
@Kikobeats
Kikobeats deleted the cursor/critical-bug-management-c688 branch September 10, 2026 13:08
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.

2 participants