Repository navigation
skip private and Vary: * responses in HttpCacheInterceptor - #3610
Conversation
velo
left a comment
There was a problem hiding this comment.
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.
…CacheInterceptor Signed-off-by: Marvin Froeder <velo.br@gmail.com>
|
I pushed the changes from the review to this branch. |
Signed-off-by: Marvin Froeder <velo.br@gmail.com> # Conflicts: # CHANGELOG.md
|
I merged master again. The CHANGELOG entry is gone because |
Repro: two callers share one client and both
GET /things/42; the origin answers the first withCache-Control: private,ETag: "v1"and that caller's data, then answers the second caller's revalidation with304.Expected: the second caller gets its own data, or the
304surfaces.Actual: the second caller is handed the first caller's decoded object.
Cause:
maybeStoreonly refusesno-store, so aprivateresponse (RFC 9111 5.2.2.7, a shared cache must not store it) and aVary: *response (RFC 9111 4.1,*never matches a later request) both land in theHttpCacheStoreevery caller of the client shares, under a default key ofconfigKey|METHOD url[|body hash]that carries no request header. The stored validator then goes out on the next caller's request asIf-None-Match.Fix: treat both as unstorable alongside
no-store.Varyfield names other than*are untouched, soVary: Accept-Encodingand friends still cache as before, and the README caveat about uninterpretedCache-Controldirectives is narrowed to freshness, which revalidation already covers.