缓存控制中 max-age=0 和 max-age=-1 有什么区别?
What is the difference between max-age=0 and max-age=-1 in Cache Control?
两个 headers Cache-control: max-age=0
和 Cache-control: max-age=-1
之间的浏览器行为有何不同?
如果浏览器收到max-age=0,它会立即重新验证缓存。
如果浏览器收到 max-age=10,它会在 10 秒后重新验证缓存。
max-age=-1 的浏览器行为是什么?和max-age=0一样吗?如果是,为什么我们需要两者?
max-age
takes an argument that matches delta-seconds
:
The delta-seconds rule specifies a non-negative integer, representing
time in seconds.
delta-seconds = 1*DIGIT
max-age=-1
因此不是有效的指令,并且规范没有定义解释。规范建议:
Caches are
encouraged to consider responses that have invalid freshness
information to be stale.
来自https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3
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.
来自https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
delta-seconds
Maximum number of seconds the results can be cached.
Firefox caps this at 24 hours (86400 seconds) and Chromium at 10 minutes (600 seconds). Chromium also specifies a default value of 5 seconds.
A value of -1 will disable caching, requiring a preflight OPTIONS check for all calls.
两个 headers Cache-control: max-age=0
和 Cache-control: max-age=-1
之间的浏览器行为有何不同?
如果浏览器收到max-age=0,它会立即重新验证缓存。 如果浏览器收到 max-age=10,它会在 10 秒后重新验证缓存。 max-age=-1 的浏览器行为是什么?和max-age=0一样吗?如果是,为什么我们需要两者?
max-age
takes an argument that matches delta-seconds
:
The delta-seconds rule specifies a non-negative integer, representing
time in seconds.
delta-seconds = 1*DIGIT
max-age=-1
因此不是有效的指令,并且规范没有定义解释。规范建议:
Caches are
encouraged to consider responses that have invalid freshness
information to be stale.
来自https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3
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.
来自https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
delta-seconds Maximum number of seconds the results can be cached. Firefox caps this at 24 hours (86400 seconds) and Chromium at 10 minutes (600 seconds). Chromium also specifies a default value of 5 seconds. A value of -1 will disable caching, requiring a preflight OPTIONS check for all calls.