我读过有关单个缓存控制 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/