feat(proxy-cache): honor Vary header for memory strategy#13376
Draft
shreemaan-abhishek wants to merge 2 commits into
Draft
feat(proxy-cache): honor Vary header for memory strategy#13376shreemaan-abhishek wants to merge 2 commits into
shreemaan-abhishek wants to merge 2 commits into
Conversation
Implement RFC 9111 §4.1 secondary cache key handling for the in-memory
cache. Cache entries are now partitioned by the request's values for
each header listed in the upstream Vary response, so a response cached
under one set of Vary header values is not returned to a request with
different values. Responses carrying `Vary: *` are treated as not
reusable and are not cached.
Storage layout:
- `<base_key>::__vary` holds the variant index `{vary, variants, version}`.
- `<base_key>::<md5(values)>` holds each variant body+headers.
PURGE walks every variant under a base key. CACHE_VERSION is bumped to
2 so any in-flight v1 entries are purged on read via the existing
version-mismatch path. The disk strategy is unchanged: NGINX's native
`proxy_cache` already honors Vary.
- Bound the per-base-key `variants` list to MAX_VARIANTS (64) with FIFO eviction. Without this, a Vary on a high-cardinality header would grow the index until it exceeds the shdict slot capacity and writes start failing with "no memory". - Make the `Vary: *` test deterministic: call `ngx.update_time()` in the fixture and sleep briefly between requests so the body comparison cannot tie on a single nginx time tick. - Trim two over-detailed comments in the handler.
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.
Description
The memory cache strategy previously ignored the upstream
Varyresponse header, so requests that differed only in a Vary'd header (e.g.Accept-Encoding) collided on the same cache entry. The disk strategy already inherits Vary handling from NGINX's nativeproxy_cache; this PR brings the memory strategy in line.What changes:
Varyheader into a canonical sorted list of lowercased header names.<base_key>::__varydescribing the Vary headers and known variants for that base key.<base_key>::<md5(request values)>.Vary: *is treated as not reusable per RFC 9111 §4.1 and is not cached.PURGEwalks every variant under a base key.CACHE_VERSIONis bumped from 1 to 2 so any pre-Vary entries get purged on read via the existing version-mismatch path.The disk handler is intentionally unchanged.
Which issue(s) this PR fixes:
Fixes #
Checklist
Notes
t/plugin/proxy-cache/memory.twere added (TEST 41–44) but I have not run the suite locally on this branch.proxy_cachealready handlesVary.