AWS CloudFront 最大 TTL 和默认 TTL 缓存行为的差异

Difference in AWS CloudFront Maximum TTL and Default TTL cache behavior

AWS CloudFront 默认缓存行为允许自定义最小 TTL、最大 TTL 和默认 TTL 值。我反复浏览文档,但无法理解默认 TTL 和最大 TTL 之间的实际区别。例如,如果我在默认 TTL 中给出 24 小时(以秒为单位),那么我在最大 TTL 中应用的不同持续时间会发生什么?

据我所知:

  • 当缓存控件headers不提供缓存时长
  • 时使用默认值
  • 最大 可以通过强制缩短缓存持续时间
  • 来覆盖缓存控制headers

例如,如果应用程序通过 headers 将缓存持续时间设置为 90 分钟,但最大 TTL 设置为 60 分钟,则 CloudFront 将缓存 60 分钟。

查看文档:Specifying How Long Objects Stay in a CloudFront Edge Cache (Expiration)

是的,只是添加到@John Rotenstein 的回答中:

Min TTLMax TTL 只是设置 Cloudfront 允许请求 headers 更改 TTL 的范围。如果没有传递 headers,将使用默认 TTL。

你可以在这里看到每个的定义: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesMinTTL

在实践中,我们发现如果没有传递任何内容,默认 TTL 并不总是被设置。因此,最好发送 Control max-age(或 E​​xpires)或 Cache-Control s-maxage headers 以确保 objects 在正确的时间被缓存。或者您可以将最小 TTL 和默认 TTL 设置为相同的时间。

另一件要记住的事情(来自文档):

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

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.