cache-control header 中多个值的含义

meaning of multiple values in cache-control header

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

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

我很困惑这个 header 实际上告诉了什么,因为它一次包含 4 个值。那么如果通过网络发送的资源包含 header 会怎样?

编辑:

no-store 表示 "do not store at all, not in private not public caches",no-cache 表示 "yeees you can cache, but make sure you revalidate for freshness when resource is requested"。私人说 "you can store in the private caches"。它不能同时执行所有 3 个操作。但是,我们在这里让他们同时发送响应。看起来还有一些我不知道的附加规则。

这些是一些很好的参考资料:http://dev.mobify.com/blog/beginners-guide-to-http-cache-headers/ and How to control web page caching, across all browsers?

RFC 7234 是 header 的准确含义的很好参考。

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

他们绝对可以。这些指令是多余的,但并不矛盾。 no-cache:

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

no-store

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

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

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.

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