Today’s tech tip
Did you know that you can sometimes use cache responses even if they’re stale?
This applies if the Request Cache-Control
header contains the max-stale=N
directive OR the Cached Response’s Cache-Control
header contains stale-if-error=N
or stale-if-revalidate=N
. In either of these cases we can still use a cached response for N
seconds after it went stale!
Very useful for implementing more complex, conditional caching strategies.
Example
If we sent the request below, we would be telling the cache that it may reuse a response as long as it is not older than 5 days (max-age=18000
). Additionally the cache MAY reuse the response for a further 2 days max-stale=7200
if it has any reason to (e.g. it has trouble contacting the origin server).
References: