Reputation: 1164
I had naively assumed that if I enabled the cache-control, and the client made 2 different requests with different header parameter values, the browser/server would serve both requests independently, without any caching.
I found out the painful way that this isn't actually true. Even if the request header's parameter value changes, the first response is still cached and served for the 2nd request.
Is there any definitive list of cache-control's behavior regarding which constitutes a "cache hit" and what constitutes a "cache miss"?
Some different factors I can currently think of:
I can tell from my experience that number 6 is definitely ignored for the purposes for determining if a request is a cache-hit.
From some research I've done, factors 1 and 2 seem to be evaluated when determining if something is a cache-hit.
What about the others?
Upvotes: 5
Views: 4507
Reputation: 31095
See RFC 7234 for the specification.
In particular:
The primary cache key consists of the request method and target URI.
Also note that:
When presented with a request, a cache MUST NOT reuse a stored response, unless: ... selecting header fields nominated by the stored response (if any) match those presented (see Section 4.1)
and also:
When a cache receives a request that can be satisfied by a stored response that has a Vary header field (Section 7.1.4 of [RFC7231]), it MUST NOT use that response unless all of the selecting header fields nominated by the Vary header field match in both the original request (i.e., that associated with the stored response), and the presented request.
That is, headers are assumed not to be significant unless the server responds with Vary:
and specifies that header.
Upvotes: 7