缓存控制标头中多个值的含义 [英] meaning of multiple values in cache-control header
问题描述
我已经阅读了有关单个缓存控制标头值的信息.为了测试我学到的东西,我打开了facebook并进行了检查.这是我得到的Cache-Control响应标头:
I've read about single cache-control header value. To test what I learned, I opened facebook and inspect. This is the Cache-Control response header I get:
cache-control:private, no-cache, no-store, must-revalidate
我很困惑此标头实际告诉我们的内容,因为它一次包含4个值.那么,通过网络发送的资源(如果包含此类标头)会发生什么情况?
I am confused what this header actually tells, because it contains 4 values at once. So what happens with the resource send through the network, if it contains such header?
no-store表示根本不存储,不存储在私有非公共缓存中",no-cache表示可以缓存,但是请确保在请求资源时重新验证新鲜度".私人说:您可以存储在私人缓存中".它不能同时完成所有3个操作.但是,在这里,我们让它们同时发送响应.似乎还有一些我不知道的其他规则.
no-store says, "do not store at all, not in private not public caches", and no-cache says "yeees you can cache, but make sure you revalidate for freshness when resource is requested". Private says "you can store in the private caches". It cant do all 3 at the same time. But yet, here we are having them send in response at the same time. Looks like there are some additional rules I am not aware of.
推荐答案
RFC 7234 是一个标题的准确含义很好的参考.
RFC 7234 is a good reference for the precise meaning of the headers.
无缓存和无存储意味着不同的东西,例如不能同时服从.
no-cache and no-store mean different things and cannot be obeyed at the same time for example.
他们绝对可以.这些指令是多余的,但并不矛盾.无缓存
:
They absolutely can. The directives are redundant, but not contradictory. no-cache
:
表示不得使用缓存存储的响应,无法成功满足请求在原始服务器上进行验证.
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
.其他标头类似;我相信:
As no-store
is essentially stricter than no-cache
, the result is effectively no-store
. Similarly for the other headers; I believe:
Cache-control: no-store
将是获得相同结果的一种更简单的方法.但是,您看到的标头可能是建议的组合,而不是故意的一致策略.
would be a simpler way to get the same result. However, it's possible that the header you're seeing is a combination of advice, rather than an intentionally consistent policy.
请注意,如规范所说一样,重复了指令可能无效:
Note that, as the spec says, duplicated directives may be invalid:
当给定指令存在多个值时(例如,两个Expires标头字段,多个Cache-Control:max-age指令),则该指令的值被视为无效.缓存是鼓励考虑新鲜度无效的回复信息陈旧.
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.
但是我不认为这是事实.
but I don't believe that's the case here.
这篇关于缓存控制标头中多个值的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!