Skip to content

skip private and Vary: * responses in HttpCacheInterceptor - #3610

Merged
velo merged 4 commits into
OpenFeign:masterfrom
alhudz:http-cache-shareable-responses
Nov 9, 2026
Merged

velo merged 4 commits into
OpenFeign:masterfrom
alhudz:http-cache-shareable-responses

Conversation

@alhudz

@alhudz alhudz commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Repro: two callers share one client and both GET /things/42; the origin answers the first with Cache-Control: private, ETag: "v1" and that caller's data, then answers the second caller's revalidation with 304.
Expected: the second caller gets its own data, or the 304 surfaces.
Actual: the second caller is handed the first caller's decoded object.
Cause: maybeStore only refuses no-store, so a private response (RFC 9111 5.2.2.7, a shared cache must not store it) and a Vary: * response (RFC 9111 4.1, * never matches a later request) both land in the HttpCacheStore every caller of the client shares, under a default key of configKey|METHOD url[|body hash] that carries no request header. The stored validator then goes out on the next caller's request as If-None-Match.
Fix: treat both as unstorable alongside no-store. Vary field names other than * are untouched, so Vary: Accept-Encoding and friends still cache as before, and the README caveat about uninterpreted Cache-Control directives is narrowed to freshness, which revalidation already covers.

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the Vary: * part is correct and I'd take it as is. The private part needs another pass before it can go in.

HttpCacheInterceptor.java:160 makes every Cache-Control: private response unstorable. Most Feign clients are built per credential, which makes the store a private cache in RFC 9111 terms, and those are allowed to store private responses. Authenticated APIs mark nearly everything private. GitHub, for example, sends private, max-age=60 with an ETag on every authenticated call. So this change would quietly switch caching off for the main use case of this module. The leak you describe is real, but only for a client that sends requests from several principals through one store and keeps the default key.

Suggested fix: keep the current behaviour by default and add an opt-in on the interceptor, next to key(...) and cacheable(...). Something like sharedCache(true), which skips private responses (private=\"field\" included). Then document in the README that a multi-principal client must either enable it or put the credential in keyFn. Please add a test that a private response is still stored by default, and keep privateResponseIsNotRevalidatedForASecondCaller with the option turned on. A CHANGELOG entry under 13.18 would be good too.

@velo

velo commented Nov 9, 2026

Copy link
Copy Markdown
Member

I pushed the changes from the review to this branch. private responses are stored again by default. A new HttpCacheInterceptor.sharedCache(true) option skips them, private="field" included. Vary: * is still never stored. The README now says that a multi-principal client must either enable sharedCache(true) or put the credential in keyFn. I added tests showing that private is stored and revalidated by default and is not stored with sharedCache(true), and privateResponseIsNotRevalidatedForASecondCaller now runs with the option on. I also added a CHANGELOG entry under 13.18. Thanks!

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review items addressed; LGTM.

@velo
velo enabled auto-merge (squash) November 9, 2026 20:50
Signed-off-by: Marvin Froeder <velo.br@gmail.com>

# Conflicts:
#	CHANGELOG.md
@velo

velo commented Nov 9, 2026

Copy link
Copy Markdown
Member

I merged master again. The CHANGELOG entry is gone because CHANGELOG.md was removed from the repo.

@velo
velo merged commit f5f9c42 into OpenFeign:master Nov 9, 2026
3 checks passed
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