Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between max-age and max-stale in cache control mechanism

I know this is a simple question, and I am sure that no body will mark this as duplicate question, because I have searched all over the SO. so my question is what is the difference between max-age and max-stale in Cache control mechanism of Http, I've read it in here, but I felt its little complex, so if anybody can explain about this ? it would be great help

like image 686
droidev Avatar asked Nov 20 '15 04:11

droidev


People also ask

What is Max-age in Cache-Control?

max-age. The max-age=N response directive indicates that the response remains fresh until N seconds after the response is generated. Cache-Control: max-age=604800. Indicates that caches can store this response and reuse it for subsequent requests while it's fresh.

What's the difference between Cache-Control max-age 0 and no-cache?

When max-age=0 is used, the browser will use the last version when viewing a resource on a back/forward press. If no-cache is used, the resource will be refetched.

Where is Cache-Control max-age?

Cache-Control: max-age=<seconds> This directive tells the browser or intermediary cache how long the response can be used from the time it was requested. A max-age of 3600 means that the response can be used for the next 60 minutes before it needs to fetch a new response from the origin server.

What is Max-age in HTTP header?

max-age. The max-age directive states the maximum amount of time in seconds that fetched responses are allowed to be used again (from the time when a request is made). For instance, max-age=90 indicates that an asset can be reused (remains in the browser cache) for the next 90 seconds.


1 Answers

From RFC 7234:

The "max-age" request directive indicates that the client is unwilling to accept a response whose age is greater than the specified number of seconds. Unless the max-stale request directive is also present, the client is not willing to accept a stale response.

...

The "max-stale" request directive indicates that the client is willing to accept a response that has exceeded its freshness lifetime. If max-stale is assigned a value, then the client is willing to accept a response that has exceeded its freshness lifetime by no more than the specified number of seconds.

That is, max-age is the oldest that a response can be, as long as the Cache-Control from the origin server indicates that it is still fresh. max-stale indicates that, even if the response is known to be stale, you will also accept it as long as it's only stale by that number of seconds.

As per Serving Stale Responses:

A cache SHOULD generate a Warning header field with the 110 warn-code (see Section 5.5.1) in stale responses.

So, if you specified max-stale and received a no-longer-fresh response, the Warning header would let you know.

like image 147
Joe Avatar answered Oct 02 '22 16:10

Joe