http - Cache-Control 是 :must-revalidate obliging to validate all requests, 还是陈旧的?

标签 http caching http-caching

我对这个 header 一团糟,我读过 Cache-Control:must-revalidate 必须在提供缓存项之前使用源验证所有请求,但只是陈旧的?或者不管是陈旧的还是新鲜的?我在不同的地方读过这两本书。

Cache-Control:no-cache 有什么区别?因为这些 header 看起来和我一样。

更新 1:我从一本书中读到:

The Cache-Control: must-revalidate response header tells the cache to bypass the freshness calculation mechanisms and revalidate on every access:

@Peter O. 指出了 RFC 的内容。所以那本旧书是错的。

更新 2: 在本教程中:http://www.mnot.net/cache_docs/

no-cache — forces caches to submit the request to the origin server for validation before releasing a cached copy, every time. This is useful to assure that authentication is respected (in combination with public), or to maintain rigid freshness, without sacrificing all of the benefits of caching.

must-revalidate — tells caches that they must obey any freshness information you give them about a representation. HTTP allows caches to serve stale representations under special conditions; by specifying this header, you’re telling the cache that you want it to strictly follow your rules.

最佳答案

14.9.4 HTTP/1.1 的:

When the must-revalidate directive is present in a response received by a cache, that cache MUST NOT use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server

HTTP/1.1 的第 14.8 节:

If the response includes the "must-revalidate" cache-control directive, the cache MAY use that response in replying to a subsequent request. But if the response is stale, all caches MUST first revalidate it with the origin server...

所以看起来只有过时的响应必须重新验证,如果 must-revalidate 已收到。

对于 no-cache,请参阅第 14.9.1 节:

If the no-cache directive does not specify a field-name [which is the case here], then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server...

因此,no-cache 适用于新鲜和过时的响应。

编辑:

此短语可能与此处相关(第 13.3 节):

When a cache has a stale entry that it would like to use as a response to a client's request, it first has to check with the origin server (or possibly an intermediate cache with a fresh response) to see if its cached entry is still usable.

因此,must-revalidate 可能与缓存有中间值时相关 缓存,否则缓存可以检查中间缓存 新鲜响应而不是直接检查源服务器。

关于http - Cache-Control 是 :must-revalidate obliging to validate all requests, 还是陈旧的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7573466/

相关文章:

http - AngularJS 不断从 html 模板调用 $http.get,而不是从 Controller 内部调用?

angular - Angular Service Worker和index.html缓存

c# - ASP.Net CacheDependency 对象问题

http - 如何调试来自 HTTP 调用的 http 响应 header

http - go 中的路由处理

php - 从另一台机器连接到 react 服务器

django - 我可以在 Django 缓存中获取指定键的过期时间吗?

http - Etag 和 Expires header 有什么区别?

tomcat - 页面未在浏览器中缓存

ssl - TLS 握手和 SSL session 重用