我最近浏览了 this文章。它说不仅响应,请求还可以包括cache-control
选项。
虽然我明白,它可以被服务器响应有意义地利用,但我不清楚为什么在请求中需要它们。不幸的是,我在互联网上找不到任何问题的答案。
有人有想法吗?
最佳答案
HTTP/1.1 缓存和控制缓存行为的相关 header 在 RFC 7234 中定义.不过,缓存是 HTTP 的一项完全可选的功能。
Cache-Control
header 用于为请求/响应链中的缓存指定指令。这样的缓存指令是
单向的,因为请求中存在指令并不意味着响应中会给出相同的指令。
Cache directives are identified by a token, to be compared case-insensitively, and have an optional argument, that can use both token and quoted-string syntax. For the directives defined below that define arguments, recipients ought to accept both forms, even if one is documented to be preferred. For any directive not defined by this specification, a recipient MUST accept both forms.
Cache-Control = 1#cache-directive cache-directive = token [ "=" ( token / quoted-string ) ]
在 directives 下面找到可用于 Cache-Control
的请求中 header :
[...] 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. [...]This directive uses the token form of the argument syntax: e.g.,
max-age=5
notmax-age="5"
. [...]
[...] The
max-stale
request directive indicates that the client is willing to accept a response that has exceeded its freshness lifetime. [...]This directive uses the token form of the argument syntax: e.g.,
max-stale=10
notmax-stale="10"
. [...]
[...] The
min-fresh
request directive indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified time in seconds. [...]This directive uses the token form of the argument syntax: e.g.,
min-fresh=20
notmin-fresh="20"
. [...]
The
no-cache
request directive indicates that a cache MUST NOT use a stored response to satisfy the request without successful validation on the origin server.
The
no-store
request directive indicates that a cache MUST NOT store any part of either this request or any response to it. [...]
The
no-transform
request directive indicates that an intermediary (whether or not it implements a cache) MUST NOT transform the payload [...].
The
only-if-cached
request directive indicates that the client only wishes to obtain a stored response. [...]
以类似的方式,RFC 7234还定义了 directives可用于 Cache-Control
的响应中标题。
关于http - 为什么要为请求缓存控制 HTTP header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47507679/