[英]What is the difference between no-cache and no-store in Cache-control?
I don't find get the practical difference between Cache-Control:no-store
and Cache-Control:no-cache
.我没有发现
Cache-Control:no-store
和Cache-Control:no-cache
之间的实际区别。
As far as I know, no-store
means that no cache device is allowed to cache that response.据我所知,
no-store
意味着不允许缓存设备缓存该响应。 In the other hand, no-cache
means that no cache device is allowed to serve a cached response without validate it first with the source.另一方面,
no-cache
意味着不允许任何缓存设备在不首先使用源验证缓存响应的情况下提供缓存响应。 But what is that validation about?但这种验证是关于什么的? Conditional get?
有条件搞定?
What if a response has no-cache
, but it has no Last-Modified
or ETag
?如果响应有
no-cache
,但没有Last-Modified
或ETag
怎么办?
Regards.问候。
See the below flow chart for better understanding 有关更好的理解,请参阅下面的流程图
Ref: ( https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en#cache-control ) 参考:( https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching?hl=en#cache-control )
But what is that check about?
但那检查是什么?
Exactly checking Last-Modified
or ETag
. 正确检查
Last-Modified
或ETag
。 Client would ask server if it has new version of data using those headers and if the answer is no it will serve cached data. 客户端会询问服务器是否有使用这些标头的新版本数据,如果答案为否,它将提供缓存数据。
Update 更新
no-cache
If the no-cache directive does not specify a field-name, then a cache MUST NOT use
the response to satisfy a subsequent request without successful revalidation with the
origin server. This allows an origin server to prevent caching even by caches that
have been configured to return stale responses to client requests.
As you identified, no-cache doesn't mean there is never caching, but rather that the user agent has to always ask the server if it's OK to use what it cached. 正如您所指出的,no-cache并不意味着永远不会缓存,而是用户代理必须始终询问服务器是否可以使用缓存的内容。 By contrast, no-store says to not even keep a copy, which means there's nothing to ask about.
相比之下,没有商店说甚至不保留副本,这意味着没有什么可以问的。 If you know the answer to "Can I reuse this?"
如果你知道答案“我可以重复使用吗?” is always no, you get a performance boost by skipping cache validation and saving room in the cache for other data.
永远不行,您可以通过跳过缓存验证并在缓存中为其他数据节省空间来提升性能。
Aside from performance, there is a behavior difference with browser history . 除了性能之外, 浏览器历史记录还存在行为差异。 HTTP 1.1 section 13.13 says that "expiration time does not apply to history mechanisms."
HTTP 1.1第13.13节说“过期时间不适用于历史机制”。 The no-cache header describes expiration, and so doesn't apply to history mechanisms such as the back button.
no-cache标头描述了到期,因此不适用于历史机制,例如后退按钮。 Thus, the user can navigate backward to a previous page with no-cache without the server being contacted.
因此,用户可以在没有联系服务器的情况下向后导航到没有高速缓存的前一页。
The no-store header, on the other hand, prevents the data from being stored outside of a session, in which case it simply isn't available for a history mechanism to use. 另一方面,no-store标头阻止数据存储在会话之外,在这种情况下,它根本不可用于历史机制。 With no-store, if the user ends his session by navigating to another domain and then goes back, the only way for browser to know what to display is to get the initial page again from the server.
如果用户没有存储,如果用户通过导航到另一个域结束其会话然后返回,则浏览器知道要显示的内容的唯一方法是从服务器再次获取初始页面。
Here's how a Chromium issue on this topic makes the distinction: 以下是关于此主题的Chromium问题如何区分:
no-cache doesn't mean "don't cache this" (that would be no-store).
no-cache并不意味着“不要缓存这个”(这将是无商店)。 no-cache means don't use this for normal loads unless the resource is revalidated for freshness.
no-cache意味着不要将此用于正常负载,除非为新鲜度重新验证资源。 History navigations are not normal loads.
历史导航不是正常负载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.