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


当前回答

这在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.

其他回答

这是一个老问题了,但是如果有人像我一样通过搜索发现了这个问题,那么IE9似乎会在使用后退和前进按钮时利用这个来配置资源的行为。当使用max-age=0时,浏览器在向后/向前按下查看资源时将使用最近的版本。如果使用了无缓存,则会重新获取资源。

关于IE9缓存的更多细节可以在这篇msdn缓存博客文章中看到。

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

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

信息= 0

这相当于单击Refresh,这意味着给我最新的副本,除非我已经有了最新的副本。

no - cache

这是按住Shift同时点击刷新,这意味着,不管发生什么都要重做。

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

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

这在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.