Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Cache-Control:must-revalidate obliging to validate all requests, or just the stale ones?

I have a mess with this header, I have read that Cache-Control:must-revalidate oblige to validate all requests with the source before serving a cached item, but just the stale ones? or all no matter if stale or fresh? I have read both things in different places.

What is the difference with Cache-Control:no-cache ? Because these headers look equivalent to me.

UPDATE 1: I have read this from a book:

The Cache-Control: must-revalidate response header tells the cache to bypass the freshness calculation mechanisms and revalidate on every access:

@Peter O. has pointed out what the RFC says. So that old book is wrong.

UPDATE 2: In this tutorial : http://www.mnot.net/cache_docs/

no-cache — forces caches to submit the request to the origin server for validation before releasing a cached copy, every time. This is useful to assure that authentication is respected (in combination with public), or to maintain rigid freshness, without sacrificing all of the benefits of caching.

must-revalidate — tells caches that they must obey any freshness information you give them about a representation. HTTP allows caches to serve stale representations under special conditions; by specifying this header, you’re telling the cache that you want it to strictly follow your rules.

like image 787
vtortola Avatar asked Sep 27 '11 17:09

vtortola


People also ask

What is must revalidate in Cache-Control?

The must-revalidate response directive indicates that the response can be stored in caches and can be reused while fresh. If the response becomes stale, it must be validated with the origin server before reuse. Typically, must-revalidate is used with max-age .

How does cache revalidation work?

Revalidation checks occur when a browser sends a request to a cache server using If-Modified-Since or If-None-Match headers. These request headers are questions sent from the browser cache about when an object has last changed that can be answered via the ETag or Last-Modified response headers on the cache server.

Can I use stale-while-revalidate?

headers HTTP header: Cache-Control: stale-while-revalidate This feature is non-standard and should not be used without careful consideration.

What is stale-while-revalidate?

The stale-while-revalidate attribute is used by the Cache-Control header and defines an extra window of time during which a cache (proxy, user agents) can use a stale asset while it revalidates it asynchronously. This improves subsequent page load latencies as stale assets are non longer in the critical path.


1 Answers

Section 14.9.4 of HTTP/1.1:

When the must-revalidate directive is present in a response received by a cache, that cache MUST NOT use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server

Section 14.8 of HTTP/1.1:

If the response includes the "must-revalidate" cache-control directive, the cache MAY use that response in replying to a subsequent request. But if the response is stale, all caches MUST first revalidate it with the origin server...

So it appears that only stale responses must be revalidated if must-revalidate is received.

For no-cache, see section 14.9.1:

If the no-cache directive does not specify a field-name [which is the case here], then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server...

Thus, no-cache applies both to fresh and stale responses.

EDIT:

This phrase may be relevant here (section 13.3):

When a cache has a stale entry that it would like to use as a response to a client's request, it first has to check with the origin server (or possibly an intermediate cache with a fresh response) to see if its cached entry is still usable.

So, must-revalidate is probably relevant when the cache has intermediate caches, since otherwise the cache can check the intermediate cache for a fresh response rather than check the origin server directly.

like image 55
Peter O. Avatar answered Sep 29 '22 02:09

Peter O.