Repository navigation
feat(cache): key cache entries by configured vary headers - #4915
Merged
Merged
Conversation
Bundle size check
Compiler Diagnostics (tsc)
Compiler Diagnostics (typescript-go)
Reported by octocov |
Member
Author
|
Hi @yusukebe, |
HTTP Performance Benchmark
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4915 +/- ##
=======================================
Coverage 93.00% 93.01%
=======================================
Files 177 177
Lines 11999 12005 +6
Branches 3616 3621 +5
=======================================
+ Hits 11160 11166 +6
Misses 839 839 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
Hey @usualoma I considered whether there are patterns does not work, but it looks good! I'll merge this later and may include it in the next patch. Thanks! |
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
Varyheader is in use.options.varyonly affected the response headers. With this PR, it also contributes to the cache key.Vary-bearing responses uncacheable. The change preserves that fix while letting users opt back into caching where it's safe.Behavior changes
The behavior changes when
options.varyis configured:options.varyset / response has noVaryoptions.varyset / responseVaryis a subset ofoptions.varyVaryincludes a header outsideoptions.varyVary: *Because of this behavior change, requests that were previously (unintentionally) sharing the same entry under
options.varyare now split per header value, which can lower the hit rate. That said, this aligns with the intended semantics ofVaryand should be a desirable change in virtually every deployment. On the flip side, paths that producedVary-bearing responses — which were not cached at all after v4.12.18 — become cacheable again as long as theirVaryis covered byoptions.vary, which raises the hit rate there.Design note: interaction with
options.keyGeneratorUsers who already supply
options.keyGeneratormay already be folding the same request headers into the key themselves. With this change, those headers will be appended to the key a second time.I considered skipping the
options.vary-based key extension whenoptions.keyGeneratoris provided, but decided against it:options.varyextends the cache key", silently skipping that extension would violate their assumption.So when both are configured,
options.varystill contributes to the cache key unconditionally.The author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code