即使使用缓存控制,来自 cloudfront 的 RefreshHit:max-age=0,no-store [英] RefreshHit from cloudfront even with cache-control: max-age=0, no-store

查看:60
本文介绍了即使使用缓存控制,来自 cloudfront 的 RefreshHit:max-age=0,no-store的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cloudfront 正在为根本不应该缓存的请求获取 RefreshHit.

Cloudfront is getting a RefreshHit for a request that is not supposed to be cached at all.

它不应该被缓存,因为:

It shouldn't be cached because:

  1. 它有cache-control: max-age=0, no-store;
  2. 最小TTL为0;和
  3. 我已经创建了多个失效(在 /* 上)所以这个缓存的资源不是来自某些历史部署
  1. It has cache-control: max-age=0, no-store;
  2. The Minimum TTL is 0; and
  3. I've created multiple invalidations (on /*) so this cached resource isn't from some historical deploy

知道为什么我会收到 RefreshHits 吗?

Any idea why I'm getting RefreshHits?

我还尝试将 Cache-Control 修改为 cache-control no-store, stale-if-error=0,在 /* 上创建一个新的失效,现在我看到缓存命中(这次在 Firefox 中):

I also tried modifying Cache-Control to be cache-control no-store, stale-if-error=0, creating a new invalidation on /* and now I'm seeing a cache hit (this time in Firefox):

推荐答案

在与支持人员广泛讨论后,他们解释了正在发生的事情.

After talking extensively with support, they explained what's going on.

因此,如果您有 no-store 并且最小 TTL 为 0,那么 CloudFront 确实不会存储您的资源.但是,如果您的 Origin 需要很长时间来响应(很可能在高负载下),而 CloudFront 等待对请求的响应,如果它收到另一个相同的请求(与缓存键相同),那么它会向两个请求发送一个响应.这是为了减轻服务器的负载.(请参阅文档)

So, if you have no-store and a Minimum TTL of 0, then CloudFront will indeed not store your resources. However, if your Origin is taking a long time to respond (so likely under heavy load), while CloudFront waits for the response to the request, if it gets another identical request (identical with respect to the cache key), then it'll send the one response to both requests. This is in order to lighten the load on the server. (see docs)

支持人员称这些为崩溃命中"虽然我在文档中没有看到.

Support was calling these "collapse hits" although I don't see that in the docs.

因此,似乎您不能让单个 Behavior 为某些页面提供服务,而这些页面必须为每个请求提供唯一响应,同时为其他缓存页面提供服务.支持说:

So, it seems you can't have a single Behavior serving some pages that must have a unique response per request while serving other pages that are cached. Support said:

我刚刚确认,使用最小 TTL 0 和缓存控制:无存储,我们无法禁用折叠命中.如果确实需要完全禁用 Cloudfront 缓存,可以使用缓存策略 CachingDisabled

I just confirmed that, with min TTL 0 and cache-control: no-store, we cannot disable collapse hit. If you do need to fully disable cloudfront cache, you can use cache policy CachingDisabled

我们将为我们需要缓存的每个路径前缀创建一个行为.对于我们的用例来说,似乎没有比这更好的方法(一次将我们的网站从不可缓存的、后端渲染的 jinja2/jQuery 转换为可缓存的、客户端渲染的 React/Next.js).

We'll be making a behavior for every path prefix that we need caching on. It seems there was no better way than this for our use-case (transitioning our website one page at a time from a non-cacheable, backend-rendered jinja2/jQuery to a cacheable, client-side rendered React/Next.js).

这篇关于即使使用缓存控制,来自 cloudfront 的 RefreshHit:max-age=0,no-store的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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