CloudFront 中的 TTL 0 有什么用? [英] What is a TTL 0 in CloudFront useful for?

查看:39
本文介绍了CloudFront 中的 TTL 0 有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几周前亚马逊宣布他们降低了内容有效期:

Some weeks ago Amazon announced that they have lowered the content expiration period:

Amazon CloudFront 降低最低限度内容有效期

现在您实际上可以将 CloudFront 中的 TTL 设置为 0.所以我的问题是,为什么将 TTL 设置为 0 的 CloudFront 分配有用.对我来说,这意味着根本没有缓存,因此每个请求到达 CloudFront 最终会到达原点.

So much that you can actually set now TTL in CloudFront to 0. So my question is, why could it be useful to have a CloudFront distribution with TTL set to 0. To me this means no caching at all so every request that gets to CloudFront will end up hitting the origin.

我错过了什么?

推荐答案

Amazon CloudFront 实际上对许多用例都非常有用,因为击中原点的工作方式与乍一看有些不同,并且不一定是问题,相反;虽然此功能已较早发布,但它与最近发布的 Amazon CloudFront - 支持动态内容,例如对于手头的问题:

This new feature of Amazon CloudFront is actually extremely useful for many use cases, because hitting the origin works a bit different than it looks at first sight and is not necessarily a problem, to the contrary; while this feature has been released earlier already, it all comes together with the recent release of Amazon CloudFront - Support for Dynamic Content, e.g. for the question at hand:

可变生存时间 (TTL) - 在许多情况下,动态内容要么是在很短的时间内不可缓存或可缓存,也许只需几秒钟.过去,CloudFront 的最小 TTL 为 60分钟,因为所有内容都被认为是静态的.新的最小 TTL值为 0 秒.如果您将特定来源的 TTL 设置为 0,CloudFront 仍会缓存来自该来源的内容.然后它会发出带有 If-Modified-Since 标头的 GET 请求,从而给出源有机会表示 CloudFront 可以继续使用缓存的内容,如果它在原点没有改变.[强调我的]

Variable Time-To-Live (TTL) - In many cases, dynamic content is either not cacheable or cacheable for a very short period of time, perhaps just a few seconds. In the past, CloudFront's minimum TTL was 60 minutes since all content was considered static. The new minimum TTL value is 0 seconds. If you set the TTL for a particular origin to 0, CloudFront will still cache the content from that origin. It will then make a GET request with an If-Modified-Since header, thereby giving the origin a chance to signal that CloudFront can continue to use the cached content if it hasn't changed at the origin. [emphasis mine]

换句话说,使用 0 的 TTL 主要意味着 CloudFront 将缓存控制的权限委托给源,即源服务器决定是否,以及是否 CloudFront 缓存对象的时间;请特别注意,带有 If-Modified-Since 标头的 GET 请求并不一定意味着从源检索对象本身,而是源可以(并且应该)返回 HTTP 状态代码 304 - 未修改(如适用):

In other words, using a TTL of 0 primarily means, that CloudFront delegates the authority for cache control to the origin, i.e. the origin server decides whether or not, and if for how long CloudFront caches the objects; please note specifically, that a GET request with an If-Modified-Since header doesn't necessarily mean that the object itself is retrieved from the origin, rather the origin can (and should) return the HTTP status code 304 - Not Modified where applicable:

表示资源自上次请求后未被修改.[...]使用它可以节省服务器和服务器上的带宽和重新处理客户端,因为只有头数据必须发送和接收与被重新处理的整个页面的比较服务器,然后使用服务器和客户端的更多带宽再次发送.[强调我的]

Indicates the resource has not been modified since last requested. [...] Using this saves bandwidth and reprocessing on both the server and client, as only the header data must be sent and received in comparison to the entirety of the page being re-processed by the server, then sent again using more bandwidth of the server and client. [emphasis mine]

请参阅 Mark Nottingham 出色的缓存教程,了解有关 HTTP 缓存控制的机制和优势的详细信息,HTTP 架构中非常重要和有效的部分.

See Mark Nottingham's excellent Caching Tutorial for details on the mechanics and benefits of HTTP cache control, a really important and effective part of the HTTP architecture.

了解所有这些部分如何协同工作确实有点困难,因此在指定对象在 CloudFront 边缘缓存中的停留时间(对象过期) 尝试总结在上下文中应用时的效果CloudFront 的具体有或没有 TTL = 0.

Understanding how all these parts work together can be a bit difficult indeed, accordingly the table in section Specifying the Minimum Time that CloudFront Caches Objects for Download Distributions within Specifying How Long Objects Stay in a CloudFront Edge Cache (Object Expiration) attempts to summarize the effects when applied in the context of CloudFront with or without TTL = 0 specifically.

这篇关于CloudFront 中的 TTL 0 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆