amazon-cloudfrontcache-control

How does CloudFront behave if no Cache-Control header is set on the origin response?


I have an origin which doesn't set Cache-Control headers in its response. It appears as if those responses are not being cached by CloudFront (I never see an x-cache: Hit from cloudfront header), but I am wondering if this behaviour is documented anywhere.

It seems like those requests could be collapsed by CloudFront:

However, if there are simultaneous requests for the same object—that is, if additional requests for the same object (with the same cache key) arrive at the edge location before CloudFront receives the response to the first request—CloudFront pauses before forwarding the additional requests to the origin. This brief pause helps to reduce the load on the origin. CloudFront sends the response from the original request to all the requests that it received while it was paused. This is called request collapsing.

...

If you would like to prevent request collapsing for specific objects, you can set the minimum TTL for the cache behavior to 0 and configure the origin to send Cache-Control: private, Cache-Control: no-store, Cache-Control: no-cache, Cache-Control: max-age=0, or Cache-Control: s-maxage=0.

This alone is enough reason to set a Cache-Control header to disable request collapsing, but I'm curious what CloudFront's default caching behaviour is if a Cache-Control header is missing, and the minimum TTL is set to 0.


Solution

  • You can find this in the CloudFront documentation:

    [If] the origin does not add a Cache-Control: max-age directive to the object [and] Minimum TTL = 0 [then] CloudFront caches the object for the value of the CloudFront default TTL.

    The table there lays out how different combinations of header values and settings affect CloudFront's caching behavior.