header Cache-Control: max-age=0意味着内容被认为是过期的(必须立即重新获取),这实际上与Cache-Control: no-cache是一样的。


当前回答

max-age
    When an intermediate cache is forced, by means of a max-age=0 directive, to revalidate 
its own cache entry, and the client has supplied its own validator in the request, the 
supplied validator might differ from the validator currently stored with the cache entry. 
In this case, the cache MAY use either validator in making its own request without 
affecting semantic transparency. 

    However, the choice of validator might affect performance. The best approach is for the 
intermediate cache to use its own validator when making its request. If the server replies 
with 304 (Not Modified), then the cache can return its now validated copy to the client 
with a 200 (OK) response. If the server replies with a new entity and cache validator, 
however, the intermediate cache can compare the returned validator with the one provided in 
the client's request, using the strong comparison function. If the client's validator is 
equal to the origin server's, then the intermediate cache simply returns 304 (Not 
Modified). Otherwise, it returns the new entity with a 200 (OK) response. 

    If a request includes the no-cache directive, it SHOULD NOT include min-fresh, 
max-stale, or max-age. 

礼貌:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html # sec14.9.4

不要接受这个答案-我必须读它才能理解它的真正用法:)

其他回答

max-age
    When an intermediate cache is forced, by means of a max-age=0 directive, to revalidate 
its own cache entry, and the client has supplied its own validator in the request, the 
supplied validator might differ from the validator currently stored with the cache entry. 
In this case, the cache MAY use either validator in making its own request without 
affecting semantic transparency. 

    However, the choice of validator might affect performance. The best approach is for the 
intermediate cache to use its own validator when making its request. If the server replies 
with 304 (Not Modified), then the cache can return its now validated copy to the client 
with a 200 (OK) response. If the server replies with a new entity and cache validator, 
however, the intermediate cache can compare the returned validator with the one provided in 
the client's request, using the strong comparison function. If the client's validator is 
equal to the origin server's, then the intermediate cache simply returns 304 (Not 
Modified). Otherwise, it returns the new entity with a 200 (OK) response. 

    If a request includes the no-cache directive, it SHOULD NOT include min-fresh, 
max-stale, or max-age. 

礼貌:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html # sec14.9.4

不要接受这个答案-我必须读它才能理解它的真正用法:)

One thing that (surprisingly) hasn't been mentioned is that a request can explicitly indicate that it will accept stale data, using the max-stale directive. In that case, if the server responded with max-age=0, the cache would merely consider the response stale, and would be free to use it to satisfy the client's request [which asked for potentially-stale data]. By contrast, if the server sends no-cache that really does trump any request by the client (with max-stale) for stale data, as the cache MUST revalidate.

我不是缓存专家,但Mark Nottingham是。这里是他的缓存文档。他在参考资料部分也有很好的链接。

根据我对这些文档的阅读,它看起来像max-age=0可以允许缓存发送缓存的响应到“同一时间”的请求,其中“同一时间”意味着足够接近,它们看起来与缓存同步,但无缓存不会。

我也有同样的问题,在我的搜索中找到了一些信息(你的问题是结果之一)。这是我的决定……

Cache-Control头有两个面。一边是它可以发送的web服务器(aka。“原始服务器”)。另一边是浏览器可以发送数据的地方。“用户代理”)。


当由源服务器发送时

我相信max-age=0只是告诉缓存(和用户代理)响应从一开始就过时了,所以他们应该重新验证响应。使用If-Not-Modified头)在使用缓存副本之前,而no-cache告诉他们在使用缓存副本之前必须重新验证。从14.9.1什么是可缓存的

no - cache ...缓存绝对不能使用响应 满足后续的请求 没有成功的重新验证 源服务器。这允许 源服务器防止缓存甚至 通过已配置为 向客户端返回过时的响应 请求。

换句话说,缓存有时可能会选择使用过时的响应(尽管我认为它们必须添加一个警告标头),但无缓存表示无论如何都不允许使用过时的响应。在页面中生成棒球统计数据时,您可能希望使用SHOULD-revalidate行为,但在生成对电子商务购买的响应时,可能希望使用MUST-revalidate行为。

虽然您在评论中说无缓存不应该阻止存储是正确的,但在使用无缓存时,这实际上可能是另一个区别。我看到一个页面,缓存控制指令解密,上面写着(我不能保证它的正确性):

实际上,IE和Firefox已经做到了 开始处理无缓存 指令就好像它在指令 浏览器甚至不缓存页面。 我们开始观察这种行为 大约一年前。我们怀疑 这一变化是由 广泛的(不正确的)使用 指令防止缓存。 ... 请注意,最近,“cache-control: “无缓存”也开始发挥作用 比如“禁止存放”的指令。

顺便说一句,在我看来,Cache-Control: max-age=0, must-revalidate基本上应该与Cache-Control: no-cache意思相同。因此,也许这是一种获得无缓存的MUST-revalidate行为的方法,同时避免将无缓存迁移到与无存储(即无存储)相同的事情。没有缓存)?


当由用户代理发送时

我相信shahkalpesh的答案适用于用户代理端。你也可以看看13.2.6消除多个响应的歧义。

如果一个用户代理用Cache-Control发送一个请求:max-age=0 (aka。“端到端重新验证”),然后沿途的每个缓存将重新验证其缓存条目(例如。使用If-Not-Modified报头)一直到源服务器。如果回复是304 (Not Modified),则可以使用缓存的实体。

另一方面,发送请求与Cache-Control: no-cache (aka。“端到端重新加载”)不会重新验证,服务器在响应时绝对不能使用缓存副本。

这在MDN文档中直接回答了缓存控制:

大多数HTTP/1.0缓存不支持无缓存指令,所以 历史上max-age=0被用作一种变通方法。但只有 Max-age =0可能会导致在缓存时重用一个陈旧的响应 与源服务器断开连接。必须重新验证才能解决这个问题。 这就是为什么下面的例子等同于无缓存。 Cache-Control: max-age=0,必须重新验证 但是现在,您可以简单地使用无缓存代替。

在MDN文档中也有缓存验证:

It is often stated that the combination of max-age=0 and must-revalidate has the same meaning as no-cache. Cache-Control: max-age=0, must-revalidate max-age=0 means that the response is immediately stale, and must-revalidate means that it must not be reused without revalidation once it is stale — so in combination, the semantics seem to be the same as no-cache. However, that usage of max-age=0 is a remnant of the fact that many implementations prior to HTTP/1.1 were unable to handle the no-cache directive — and so to deal with that limitation, max-age=0 was used as a workaround. But now that HTTP/1.1-conformant servers are widely deployed, there's no reason to ever use that max-age=0-and-must-revalidate combination — you should instead just use no-cache.