Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
Why doesn't Amazon CloudFront cache files in the amount of time that I specified?
2 minute read
0
I added Cache-Control or Expires headers on the Amazon CloudFront origin and specified the amount of time that my distribution caches objects. However, CloudFront doesn't cache objects for the specified time, or CloudFront doesn't cache at all.
Resolution
Confirm that the directives that you set on the Cache-Control or Expires headers don't conflict with each other. It's a best practice to use the Cache-Control max-age directive, instead of the Expires header. If you specify values for both, then CloudFront uses only the value that you set for Cache-Control max-age.
Make sure that the Minimum TTL, Default TTL, and Maximum TTL set on the CloudFront distribution don't conflict with the Cache-Control or Expires headers.
If these cache duration settings conflict with each other, then CloudFront might not cache objects for the set time or might not cache at all. The cache duration depends on the minimum TTL settings. To control the amount of time that CloudFront caches objects, see Specify the amount of time that CloudFront caches objects.
Important: If you update an origin asset with a cache header, then CloudFront reflects the change only after CloudFront makes a new request to your origin. CloudFront makes a new request to your origin when the cached asset expires in the edge locations. Then, your distribution receives a new request for the asset. To require CloudFront to reflect the update before the cached asset is set to expire, create a cache file invalidation.