http - 缓存控制 header 中多个值的含义

标签 http caching browser-cache cache-control http-caching

我读过有关单个缓存控制 header 值的信息。为了测试我学到的东西,我打开了 facebook 并进行了检查。这是我得到的 Cache-Control 响应 header :

cache-control:private, no-cache, no-store, must-revalidate

我对这个 header 的实际含义感到困惑,因为它一次包含 4 个值。那么,如果资源包含这样的 header ,那么通过网络发送的资源会怎样呢?

编辑:

no-store 说,“根本不存储,不存储在私有(private)缓存而不是公共(public)缓存中”,no-cache 说“是的,你可以缓存,但确保在请求资源时重新验证新鲜度”。私有(private)说“你可以存储在私有(private)缓存中”。它不能同时执行所有 3 个操作。但是,我们在这里让他们同时发送响应。看起来还有一些我不知道的额外规则。

最佳答案

RFC 7234是了解 header 准确含义的良好引用。

no-cache and no-store mean different things and cannot be obeyed at the same time for example.

他们绝对可以。这些指令是多余的,但并不矛盾。 无缓存:

indicates that a cache MUST NOT use a stored response to satisfy the request without successful validation on the origin server.

无商店:

indicates that a cache MUST NOT store any part of either this request or any response to it.

由于 no-store 本质上比 no-cache 更严格,因此结果实际上是 no-store。其他标题也是如此;我相信:

Cache-control: no-store

将是获得相同结果的更简单方法。但是,您看到的 header 可能是建议的组合,而不是故意一致的政策。

请注意,作为 the spec says ,重复的指令可能无效:

When there is more than one value present for a given directive (e.g., two Expires header fields, multiple Cache-Control: max-age directives), the directive's value is considered invalid. Caches are encouraged to consider responses that have invalid freshness information to be stale.

但我不认为这里是这种情况。

关于http - 缓存控制 header 中多个值的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37501479/

相关文章:

ruby - 使用 Ruby 请求 HTTP 资源时如何指定接受的内容类型?

javascript - Web 服务器是否可以仅使用 Javascript 来获取 TOR 浏览器的真实 IP?

android - getExternalCacheDir() 如何在 Android 上运行?

Android Glide 获取不到最新版图片

css - 在 symfony 中为图像添加修订号以避免浏览器缓存

cross-browser - 如何在后台预加载 JavaScript 和 CSS 文件,以便在用户进入主页时在浏览器缓存中准备好它们?

python - 如何在 Tornado 中处理对文件的 HTTP GET 请求?

linux - Linux 文件系统的 "atomic disk write"是什么?

caching - 在 DDD 应用程序中,我应该在哪一层实现从数据库中查找数据的缓存?

javascript - 浏览器后退按钮显示服务器发送的保留页面状态,但使用 javascript 完成的任何 DOM 修改都不会被保留