来自RFC2616 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.
从 RFC 的最后几行:
如果请求包含 no-cache 指令,则不应包含 min-fresh、max-stale 或 max-age。
来自13.2.6 消除多重响应的歧义部分
When a client tries to revalidate a cache entry,
and the response it receives contains a Date header that
appears to be older than the one for the existing entry,
then the client SHOULD repeat the request
unconditionally, and include
Cache-Control: max-age=0
to force any intermediate caches to validate their copies directly with the origin server, or
Cache-Control: no-cache
to force any intermediate caches to obtain a new copy from the origin server.
If the Date values are equal, then the client MAY use either response
(or MAY, if it is being extremely prudent, request a new response).
Servers MUST NOT depend on clients being able to choose
deterministically between responses generated during the same
second, if their expiration times overlap.
我的理解是,从客户端(用户代理)max-age=0
可以用作使用最新存储版本的机制,相比之下no-cache
,它将重新获取资源。
curl -I -H 'Cache-Control: no-cache' http://example.com
因此,如果使用max-age
大于零的值,则应使用与标头中接收到的日期之间的差异匹配的存储版本和max-age
.
不确定我是否正确,但我不明白。
补充类似的问题:Cache-Control: max-age=0 和 no-cache 有什么区别?