HTTP/1.1 缓存和控制缓存行为的相关标头定义在RFC 7234 https://www.rfc-editor.org/rfc/rfc7234。不过,缓存是 HTTP 的一个完全可选的功能。
The Cache-Control https://www.rfc-editor.org/rfc/rfc7234#section-5.2标头用于指定指令用于请求/响应链上的缓存。这样的缓存指令是
单向,因为请求中存在指令并不意味着响应中将给出相同的指令。
缓存指令由令牌标识,以便进行比较
不区分大小写,并且有一个可选参数,可以同时使用
标记和带引号的字符串语法。对于下面定义的指令
定义论点,接收者应该接受这两种形式,即使
据记载,其中一种是首选。对于任何未定义的指令
根据本规范,收件人必须接受这两种形式。
Cache-Control = 1#cache-directive
cache-directive = token [ "=" ( token / quoted-string ) ]
找到下面的指令 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1可以在请求中使用Cache-Control https://www.rfc-editor.org/rfc/rfc7234#section-5.2 header:
5.2.1.1.最大年龄 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1.1
[...] 这max-age
request 指令表明客户端正在
不愿意接受年龄大于自己年龄的回复
指定的秒数。 [...]
该指令使用参数语法的标记形式:例如,max-age=5
not max-age="5"
. [...]
5.2.1.2。最大陈旧 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1.2
[...] 这max-stale
request 指令表明客户端正在
愿意接受超出其新鲜度的回复
寿命。 [...]
该指令使用参数语法的标记形式:例如,max-stale=10
not max-stale="10"
. [...]
5.2.1.3。最小新鲜度 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1.3
[...] 这min-fresh
request 指令表明客户端正在
愿意接受新鲜度不低于的响应
它的当前年龄加上指定的时间(以秒为单位)。 [...]
该指令使用参数语法的标记形式:例如,min-fresh=20
not min-fresh="20"
. [...]
5.2.1.4。无缓存 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1.4
The no-cache
request 指令表明缓存不能使用
存储的响应以满足请求但未成功
在源服务器上进行验证。
5.2.1.5。无商店 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1.5
The no-store
request 指令表明缓存不能
存储此请求的任何部分或对其的任何响应。 [...]
5.2.1.6。无变换 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1.6
The no-transform
请求指令表明中介
(无论它是否实现缓存)不得转换
有效载荷[...]。
5.2.1.7。仅当缓存时 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.1.7
The only-if-cached
request指令表示客户端只
希望获得存储的响应。 [...]
以类似的方式,RFC 7234 https://www.rfc-editor.org/rfc/rfc7234还定义了指令 https://www.rfc-editor.org/rfc/rfc7234#section-5.2.2可以在响应中使用Cache-Control https://www.rfc-editor.org/rfc/rfc7234#section-5.2 header.