Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFront caching - How to ensure CF refreshes from S3 origin server after expiry?

I'm putting assets to S3 with expiry headers, which successfully get passed through to CloudFront distributions. However, requests after the expiry don't result in CloudFront requesting a fresh file from the origin server.

I am also finding that query string version tokens don't force a fresh asset, and I don't want to use full, file name versioning.

All of this may be down to my poor knowledge of cache-control headers, but I am starting to wonder if I am missing something critical about how CloudFront is supposed to work. The CloudFront responses are showing headers like the following.

Cache-Control: max-age=120
Expires: Tue, 07 Apr 2009 12:13:26 GMT
like image 217
Tim Whitlock Avatar asked Apr 07 '09 13:04

Tim Whitlock


People also ask

How do I force CloudFront to refresh?

Right click your distribution. Select "Get Cloudfront invalidation list" Then select "Create" to create a new invalidation list. Select the files to invalidate, and click "Invalidate." Wait 5-15 minutes.

What is the default expiry time for an Amazon CloudFront cache?

By default, each file automatically expires after 24 hours, but you can change the default behavior in two ways: To change the cache duration for all files that match the same path pattern, you can change the CloudFront settings for Minimum TTL, Maximum TTL, and Default TTL for a cache behavior.

How long does CloudFront take to update from S3?

Short description. By default, CloudFront caches a response from Amazon S3 for 24 hours (Default TTL of 86,400 seconds). If your request lands at an edge location that served the Amazon S3 response within 24 hours, then CloudFront uses the cached response. This happens even if you updated the content in Amazon S3.

What is the default CloudFront cache TTL when the origin server does not send specific caching directives?

Minimum TTL Specify the minimum amount of time, in seconds, that you want objects to stay in CloudFront caches before CloudFront forwards another request to your origin to determine whether the object has been updated. The default value for Minimum TTL is 0 seconds.


2 Answers

Time passes and things change. As Tim had noted, the lowest cache time was 24hrs but in April 2010 Amazon announced that they will recognize and follow directives for caching down to an hour.

Announcement here: http://developer.amazonwebservices.com/connect/ann.jspa?annID=655

like image 82
John Mark Mitchell Avatar answered Oct 17 '22 10:10

John Mark Mitchell


Looks like Amazon ignores expiry times less than 24 hours. http://developer.amazonwebservices.com/connect/thread.jspa?messageID=107699&#107699

like image 43
Tim Whitlock Avatar answered Oct 17 '22 08:10

Tim Whitlock