Repository navigation
[ISSUE #6505][ISSUE #6506] Preserve HTTP response cache semantics - #7662
Merged
Aias00 merged 2 commits intoOct 16, 2026
Merged
Conversation
Aias00
approved these changes
Oct 16, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
Review: Preserve HTTP response cache semantics (#6505 / #6506)
This is a thorough, well-engineered rewrite of the response-cache plugin. Approach and quality are strong.
What's good
- Correct cache-eligibility gate.
doExecutenow short-circuits to the chain for non-GET methods, requests withContent-Length > 0/Transfer-Encoding, and any ofAuthorization/Cookie/Range/If-*/Cache-Control/Pragma. This fixes the previous unsafe behavior where POST/PUT/etc. could be cached and served cross-request. switchOnFirstbody peeking. A GET that actually carries a body is forwarded (re-wrapped viaServerHttpRequestDecorator) without ever aggregating or caching it, and a request-body error is propagated instead of being masked by a stale hit. Nice correctness touch.- Atomic complete-response envelope. New
CachedResponsestores status + end-to-end headers + raw body as one versioned value (length-prefixed JSON metadata + bytes). This preserves redirects, error statuses, multi-value headers, absent Content-Type, and 204 — none of which the old splitdataKey/contentTypeKeyscheme handled reliably. - Safe capture timing. Snapshot is taken in
beforeCommitand persisted only after the write succeeds (doOnSuccess), with hop-by-hop headers,Set-Cookie/Vary/restrictedCache-Control, 206/304, and streaming (writeAndFlushWith) correctly excluded. Content-Length is recalculated. - Key isolation.
responseKeyfolds method + raw URI + matched selector + rule id, anddecoderejects legacy body-only / malformed envelopes as misses — no Redis migration needed, no cross-rule entry sharing. - Test coverage is excellent:
CacheRequestEligibilityTest,CacheResponseReplayTest,CachedResponseTest,CacheUtilsTestplus updatedCachePluginTestcover eligibility, status/header/body replay, cookie/vary/private exclusion, empty responses, malformed-envelope fallback, and key dimensionality.
Minor / non-blocking
CacheUtils.contentTypeKey(...)is now unused by production code (only referenced by one test assertiontestNonGetMissDoesNotWriteCache). Safe to leave, but could be removed to avoid dead surface area.dataKeystill exists for backwards compatibility; worth a short comment clarifying it is only a building block ofresponseKeynow, not a standalone cache entry.
Conclusion
Solid, safe, and well-tested. Approving. The only follow-up is to re-run the infra-level e2e / registry_dependencies jobs (which are currently red but unrelated to this change — they fail on the compose/registry setup).
Great work.
This was referenced Oct 23, 2026
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.
Fixes #6505.
Fixes #6506.
Cache hits previously replayed only the body and Content-Type, so a cached redirect lost Location/status and an error body could become a default 200 response. The path/query-only key also reused responses across HTTP methods, request bodies, authorities, encoded query strings, and matched rules.
Restrict cache use to bodyless GET requests, forwarding other requests normally. Requests carrying credentials/cookies, range or conditional headers, or client cache directives bypass both reads and writes. Inspect the actual GET body stream, replay its first buffer downstream when data is present, and release peeked pooled buffers on completion/error/cancellation. Keys include the method, complete raw URI, selector ID, and rule ID.
Store one complete response value under a separate versioned key: a length-prefixed metadata document followed by raw body bytes. Capture final application headers/status at commit after preceding callbacks, and publish the entry only after the response write succeeds. Hits restore status and end-to-end headers, preserve multi-value headers and missing Content-Type, recalculate Content-Length, and support empty/204 responses. Connection headers and Connection-nominated headers are excluded. Repeated completion is idempotent, and cache-write failures do not replace the upstream response.
Responses with cookies, Vary, private/no-store/no-cache directives, or informational/partial/not-modified statuses are not stored. Streaming writeAndFlushWith responses pass through. Invalid entries are treated as misses; old body-only/body-plus-type entries are not reused and expire under their existing TTL. The ICache backend SPI is unchanged.
docs/cache-request-eligibility.mddocuments these behavior changes and the cold-cache transition; POST and other non-GET routes now call upstream on every request.Validation:
git diff --checkpasses../mvnw clean install -Dmaven.javadoc.skip=true(affected-reactor validation above).