4

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:

  1. Query parameter keys
  2. Query parameter values
  3. Form parameter keys
  4. Form parameter values
  5. Header parameter keys
  6. Header parameter values

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?

Community
  • 1
  • 1
RvPr
  • 1,074
  • 1
  • 9
  • 26
  • Of course! There is tons of information! In general, you have to pay attention to `cache-control`, `expires` and `etag` headers – MaxXx1313 Nov 27 '15 at 18:35
  • also, if you are using proxy, it theoretically can ignore any cashe control header. You always can add some random value to request url to make it unique. – MaxXx1313 Nov 27 '15 at 18:38

1 Answers1

7

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.

Community
  • 1
  • 1
Joe
  • 29,416
  • 12
  • 68
  • 88
  • Awesome answer. If anyone is interested in further details on how to use the Vary header, [see the following](http://stackoverflow.com/questions/1700453/caching-proxy-with-authenticated-rest-requests). – RvPr Nov 30 '15 at 14:54