Skip to main content

4. The stale-if-error Cache-Control Extension

The stale-if-error Cache-Control extension indicates that when an error is encountered, a cached stale response MAY be used to satisfy the request, regardless of other freshness information.

stale-if-error = "stale-if-error" "=" delta-seconds

When used as a request Cache-Control extension, its scope of application is the request it appears in; when used as a response Cache-Control extension, its scope is any request applicable to the cached response in which it occurs.

Its value indicates the upper limit to staleness; when the cached response is more stale than the indicated amount, the cached response SHOULD NOT be used to satisfy the request, absent other information.

In this context, an error is any situation that would result in a 500, 502, 503, or 504 HTTP response status code being returned.

Note that this directive does not affect freshness; stale cached responses that are used SHOULD still be visibly stale when sent (i.e., have a non-zero Age header and a warning header, as per HTTP's requirements).

4.1. Example

A response containing:

HTTP/1.1 200 OK
Cache-Control: max-age=600, stale-if-error=1200
Content-Type: text/plain

success

indicates that it is fresh for 600 seconds, and that it may be used if an error is encountered after becoming stale for an additional 1200 seconds.

Thus, if the cache attempts to validate 900 seconds afterwards and encounters:

HTTP/1.1 500 Internal Server Error
Content-Type: text/plain

failure

the successful response can be returned instead:

HTTP/1.1 200 OK
Cache-Control: max-age=600, stale-if-error=1200
Age: 900
Content-Type: text/plain

success

After the age is greater than 1800 seconds (i.e., it has been stale for 1200 seconds), the cache must write the error message through.

HTTP/1.1 500 Internal Server Error
Content-Type: text/plain

failure