简体   繁体   English

Cache-control中no-cache和no-store有什么区别?

[英]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-storeCache-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-ModifiedETag怎么办?

Regards.问候。

But what is that check about? 但那检查是什么?

Exactly checking Last-Modified or ETag . 正确检查Last-ModifiedETag 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 更新

From RFC 来自RFC

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. 历史导航不是正常负载。

  • No-store: Client will not make any caching operation. No-store:客户端不会做任何缓存操作。
  • No-cache: Client will cache the response, but client will check server before using that cached data: "data has changed on the server or not?":with help of 'If-Modified-Since' or 'If-None-Match' header.无缓存:客户端将缓存响应,但客户端将在使用该缓存数据之前检查服务器:“服务器上的数据是否已更改?”:借助“If-Modified-Since”或“If-None-Match” ' 标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用缓存控制的缺点是:无存储? - What are the drawbacks of using cache-control: no-store? Cache-Control: max-age=0 和 no-cache 有什么区别? - What's the difference between Cache-Control: max-age=0 and no-cache? 如何找到在“私有,无存储”上设置 Cache-Control 的位置? - How to find where Cache-Control is set on "private, no-store"? Http 304&Cache-Control:无缓存 - Http 304 & Cache-Control: no-cache 请求标头“ cache-control”字段和响应标头“ cache-control”之间有什么区别? - What is the difference between request header 'cache-control' field and response header 'cache-control'? http协议中的缓存验证(缓存控制标头不缓存)有什么作用? - What does cache validation (no-cache for cache-control header) do in http protocol? 同时使用“ Expires:0”,“ no-cache”,“ no-store”,“ max-age = 0,必须重新验证”-做什么用? - Simultaneous use of “Expires: 0”, “no-cache”, “no-store”, “max-age=0, must-revalidate” - what for? 为什么在 HTTP 响应中应该同时使用 no-cache 和 no-store? - Why both no-cache and no-store should be used in HTTP response? Pragma 和 Cache-Control 标头之间的区别? - Difference between Pragma and Cache-Control headers? 什么是缓存控制:私有? - What is Cache-Control: private?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM