fix(cache): only apply 1-year deleteAt for immutable responses#4913
Merged
mcollina merged 2 commits intonodejs:mainfrom Mar 19, 2026
Merged
fix(cache): only apply 1-year deleteAt for immutable responses#4913mcollina merged 2 commits intonodejs:mainfrom
mcollina merged 2 commits intonodejs:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that: - max-age responses get deleteAt proportional to freshness lifetime (not 1 year) - immutable responses get deleteAt of ~1 year - stale-while-revalidate correctly extends deleteAt beyond staleAt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4913 +/- ##
=======================================
Coverage 92.90% 92.90%
=======================================
Files 112 112
Lines 35638 35646 +8
=======================================
+ Hits 33108 33118 +10
+ Misses 2530 2528 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merged
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.
This relates to...
determineDeleteAtinlib/handler/cache-handler.jsunconditionally applying a 1-yeardeleteAtto all responses withoutstale-while-revalidateorstale-if-errordirectives.Rationale
A
Cache-Control: max-age=60response was gettingdeleteAtset tonow + 1 yearinstead of a value proportional to its freshness lifetime. This causes cache stores (especially persistent stores like Redis/SQLite) to retain entries far longer than intended, wasting storage.The variable was named
immutablebut the condition never checked for the actualimmutablecache-control directive.Changes
Features
N/A
Bug Fixes
deleteAtfallback behind an actualcacheControlDirectives.immutablecheckdeleteAttostaleAt + freshnessLifetime(effectively 2× max-age), giving entries enough time paststaleAtfor revalidation without lingering indefinitelyBefore:
Cache-Control: max-age=60→deleteAt≈ 1 year outAfter:
Cache-Control: max-age=60→deleteAt≈ 120s out (60s fresh + 60s revalidation buffer)Note: when
immutableIS set,determineStaleAtalready returns 1 year forstaleAt, so the 1-yeardeleteAtis a belt-and-suspenders safety net for thedeleteAtside.Expected Changes
Cache entries without
immutable,stale-while-revalidate, orstale-if-errorwill now expire sooner from cache stores. This is the correct behavior per RFC 9111 but could cause more cache misses for deployments that were (incorrectly) relying on the 1-year retention.Benchmark
Status