缓存控制机制中max-age和max-stale的区别
What is difference between max-age and max-stale in cache control mechanism
我知道这是一个简单的问题,我相信没有人会把它标记为重复问题,因为我已经搜索了整个 SO。所以我的问题是 max-age 和 max-stale 在 Http 的缓存控制机制中有什么区别,我在 here 中读过它,但我觉得它有点复杂,所以如果有人能解释一下这个吗?会有很大帮助
试试这个,它用例子解释
https://msdn.microsoft.com/en-us/library/27w3sx5e(v=vs.110).aspx
来自RFC 7234:
The "max-age" request directive indicates that the client is
unwilling to accept a response whose age is greater than the
specified number of seconds. Unless the max-stale request directive
is also present, the client is not willing to accept a stale
response.
...
The "max-stale" request directive indicates that the client is
willing to accept a response that has exceeded its freshness
lifetime. If max-stale is assigned a value, then the client is
willing to accept a response that has exceeded its freshness lifetime
by no more than the specified number of seconds.
也就是说,max-age
是最旧的响应,只要 来自源服务器的 Cache-Control
表明它仍然是新鲜的。 max-stale
表示,即使已知响应已过时,只要响应仅过时该秒数,您也会接受它。
A cache SHOULD generate a Warning header field with the 110 warn-code
(see Section 5.5.1) in stale responses.
因此,如果您指定 max-stale
并收到 no-longer-fresh 响应,Warning
header 会通知您。
我知道这是一个简单的问题,我相信没有人会把它标记为重复问题,因为我已经搜索了整个 SO。所以我的问题是 max-age 和 max-stale 在 Http 的缓存控制机制中有什么区别,我在 here 中读过它,但我觉得它有点复杂,所以如果有人能解释一下这个吗?会有很大帮助
试试这个,它用例子解释
https://msdn.microsoft.com/en-us/library/27w3sx5e(v=vs.110).aspx
来自RFC 7234:
The "max-age" request directive indicates that the client is unwilling to accept a response whose age is greater than the specified number of seconds. Unless the max-stale request directive is also present, the client is not willing to accept a stale response.
...
The "max-stale" request directive indicates that the client is willing to accept a response that has exceeded its freshness lifetime. If max-stale is assigned a value, then the client is willing to accept a response that has exceeded its freshness lifetime by no more than the specified number of seconds.
也就是说,max-age
是最旧的响应,只要 来自源服务器的 Cache-Control
表明它仍然是新鲜的。 max-stale
表示,即使已知响应已过时,只要响应仅过时该秒数,您也会接受它。
A cache SHOULD generate a Warning header field with the 110 warn-code (see Section 5.5.1) in stale responses.
因此,如果您指定 max-stale
并收到 no-longer-fresh 响应,Warning
header 会通知您。