Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CloudFront make use of Cache-Control headers in error responses (e.g. 503) from the origin?

Does CloudFront make use of Cache-Control headers (e.g. max-age) in error responses (e.g. 503) from the origin? Or is the length of its caching of error responses always controlled by the Error Caching Minimum TTL configured on the distribution? The inclusion of the word "minimum" suggests that the behavior of error caching may be similar to the behavior of non-error caching when the origin provides a Cache-Control max-age, but the documentation on this topic doesn't seem to explicitly confirm that suggestion.

like image 508
Matt Avatar asked May 04 '16 14:05

Matt


1 Answers

CloudFront does respect Cache-Control max-age headers in error responses from web origins if and when they are greater than the Error Caching Minimum TTL (which has a default of five minutes).

If the origin sets a max-age that is less than the Error Caching Minimum TTL, CloudFront caches the response for the Error Caching Minimum TTL but passes the max-age set by the origin on to the client undisturbed.

Similarly, if the origin sets Cache-Control to must-revalidate,no-cache,no-store, CloudFront caches the response for the Error Caching Minimum TTL but passes the Cache-Control header set by the origin on to the client undisturbed.

The Error Caching Minimum TTL can be customized for error codes 400, 403, 404, 405, 414, 416, 500, 501, 502, 503, and 504. It can't be customized for all of the supported error codes at once; it must be customized separately for each error code. This is done by creating a "Custom Error Response." Somewhat confusingly, doing so doesn't require that you provide a custom error page. When creating the Custom Error Response you can select "No" to "Customize Error Response" (that sounds like nonsense, but it's true). If you do so, you are only customizing the Error Caching Minimum TTL for the HTTP Error Code you select.

like image 99
Matt Avatar answered Dec 09 '22 01:12

Matt