Vishal
Vishal

Reputation: 2173

Difference in AWS CloudFront Maximum TTL and Default TTL cache behavior

AWS CloudFront default cache behavior allows customizing Min TTL, Max TTL and Default TTL value. I repeatedly went through the documentation but could not understand what is actual difference between Default TTL and Maximum TTL. For example, if I give 24 hours (in seconds) in Default TTL then what happens to a different duration I apply in Max TTL?

Upvotes: 8

Views: 6035

Answers (3)

Gowtham
Gowtham

Reputation: 614

Default cache TTL: it will be applied when no headers presented in requests. Usually we do like this. This is 24 hours and we can customize if we want. If default TTL is 24 hours: 24 hours objects to stay in CloudFront caches before CloudFront forwards another request to your origin to determine whether the object has been updated.

Max and Min Cache TTL: it will be applied when requests(to access objects) with cache-headers are presented(Cache-Control max-age, Cache-Control s-maxage, or Expires). These are like boundary values if request header has Expires greater than max-TTL then consider that object expiration as max-TTL. If any object request header has Expires which is less than min-TTL then consider that expiration as min-TTL.

Upvotes: 1

nauman hafiz
nauman hafiz

Reputation: 370

yea, just to add to @John Rotenstein's answer:

Min TTL and Max TTL just set the range that Cloudfront will allow the request headers to change TTL. If no headers are passed the Default TTL will be used.

You can see the definition of each here: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesMinTTL

In practise, we have found that Default TTL does not always get set if nothing is passed. So it is good practise to send in Control max-age (or Expires) or Cache-Control s-maxage headers to ensure objects are getting cached for the correct time. Or you can set the Min TTL and default TTL to the same time.

Another thing to keep in mind (from docs):

If you configure CloudFront to forward all headers to your origin for a cache behavior, CloudFront never caches the associated objects.

Upvotes: 1

John Rotenstein
John Rotenstein

Reputation: 269480

From what I can see:

  • Default is used when the cache control headers do not provide a caching duration
  • Maximum can override the cache control headers by enforcing a shorter caching duration

For example, if the application sets the caching duration to 90 minutes via the headers, but the Maximum TTL is set to 60 minutes, then CloudFront will cache for 60 minutes.

See documentation: Specifying How Long Objects Stay in a CloudFront Edge Cache (Expiration)

Upvotes: 13

Related Questions