-
Notifications
You must be signed in to change notification settings - Fork 4
/
870.txt
169 lines (138 loc) · 9.62 KB
/
870.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
[4] [[キャッシュ]]が[[応答メッセージ]]の複製を蓄積して以後の[[要求]]に答えるために使うことが認められている時、
その[[応答]]は[DFN[[RUBYB[[[キャッシュ可能]]]@en[cacheable]]]]であるといいます [SRC[>>3]]。
;; [5] ただし[[キャッシュ可能]]であるからといっていつでもその[[応答]]を使いまわせるわけではなく、
[[要求]]が色々な条件を満たす必要があります。
[26] 本項では[[キャッシュ]]に[[蓄積]]された ([[キャッシュ項目]]に含まれる)
[[応答]]を再利用する条件についても扱います。
;; [13] [[キャッシュ可能]]な[[応答]]であっても、[[キャッシュ]]がそれを[[蓄積]]し再利用することは義務ではありません。
[[キャッシュ不可能]]な[[応答]]を[[キャッシュ]]することは禁止されていますが、
[[キャッシュ可能]]な[[応答]]が[[キャッシュ]]されて再利用されるかどうかは、
実装方法、設定、ディスク容量その他色々な状況に依存します。
* 仕様書
[REFS[
- [3] [CITE@en[RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing]] ([TIME[2014-06-07 01:59:35 +09:00]] 版) <https://tools.ietf.org/html/rfc7230#page-12>
- [6] [CITE@en[RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content]] ([TIME[2014-06-07 01:55:45 +09:00]] 版) <https://tools.ietf.org/html/rfc7231#section-4.2.3>
- [9] [CITE@en[RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content]] ([TIME[2014-06-07 01:55:45 +09:00]] 版) <https://tools.ietf.org/html/rfc7231#section-6>
- [14] [CITE@en[RFC 7234 - Hypertext Transfer Protocol (HTTP/1.1): Caching]] ([TIME[2014-09-11 10:19:59 +09:00]] 版) <https://tools.ietf.org/html/rfc7234#section-3>
-- [23] [CITE@en[RFC 7234 - Hypertext Transfer Protocol (HTTP/1.1): Caching]] ([TIME[2014-09-11 10:19:59 +09:00]] 版) <https://tools.ietf.org/html/rfc7234#section-3.2>
- [27] [CITE@en[RFC 7234 - Hypertext Transfer Protocol (HTTP/1.1): Caching]] ([TIME[2014-09-11 10:19:59 +09:00]] 版) <https://tools.ietf.org/html/rfc7234#section-4>
]REFS]
* キャッシュ可能メソッド
[7] [[応答]]を[[キャッシュ]]して再利用できる[[メソッド]]のことを、
[DFN[[RUBYB[[[キャッシュ可能]]]@en[cacheable]]]]であるといいます [SRC[>>6]]。
[8] 次の[[メソッド]]は、[[キャッシュ可能]]です [SRC[>>6]]。
[FIG(list short)[
- [CODE(HTTP)@en[[[GET]]]]
- [CODE(HTTP)@en[[[HEAD]]]]
- [CODE(HTTP)@en[[[POST]]]]
]FIG]
* キャッシュ可能な応答の状態符号
[11] 次の[[状態符号]]の[[応答]]は[[キャッシュ可能]]です。
[FIG(short list)[
- [CODE(HTTP)[[[200]]]]
- [CODE(HTTP)[[[203]]]]
- [CODE(HTTP)[[[204]]]]
- [CODE(HTTP)[[[206]]]]
- [CODE(HTTP)[[[300]]]]
- [CODE(HTTP)[[[301]]]]
- [CODE(HTTP)[[[308]]]]
- [CODE(HTTP)[[[404]]]]
- [CODE(HTTP)[[[405]]]]
- [CODE(HTTP)[[[410]]]]
- [CODE(HTTP)[[[414]]]]
- [CODE(HTTP)[[[501]]]]
]FIG]
;; [12] これらの[[状態符号]]でも、 [CODE(HTTP)@en[[[Cache-Control:]]]]
など他の条件により[[キャッシュ]]できないことがあります。
[10] 未知の[[状態符号]]の[[応答]]は、[[キャッシュ]]しては[['''なりません''']] [SRC[>>9]]。
* キャッシュ可能性の判定
[15] [[応答]]を[[蓄積]]しても構わないかどうかは、次のように決定します。
[FIG(steps)[
= [16] [[要求メソッド]]を[[キャッシュ]]が理解しないなら、
蓄積できません [SRC[>>14]]。ここで終わります。
= [17] [[要求メソッド]]が[[キャッシュ可能]]でないなら、
蓄積できません [SRC[>>14]]。ここで終わります。
= [18] [[応答]]の[[状態符号]]を[[キャッシュ]]が理解しないなら、
蓄積できません [SRC[>>14]]。ここで終わります。
= [19] [[要求]]または[[応答]]の [CODE(HTTP)@en[[[Cache-Control:]]]]
[[ヘッダー]]に [CODE(HTTP)@en[[[no-store]]]] [[キャッシュ指示子]]があるなら、
蓄積できません [SRC[>>14]]。ここで終わります。
= [22] [[共有キャッシュ]]の場合、
== [20] [[要求]]または[[応答]]の [CODE(HTTP)@en[[[Cache-Control:]]]]
[[ヘッダー]]に [CODE(HTTP)@en[[[private]]]] [[キャッシュ指示子]]があるなら、
蓄積できません [SRC[>>14]]。ここで終わります。
== [34] [[応答]]の [CODE(HTTP)@en[[[Cache-Control:]]]] [[ヘッダー]]に
[CODE(HTTP)@en[[[public]]]] か [CODE(HTTP)@en[[[s-maxage]]]]
の[[キャッシュ指示子]]があれば、蓄積できます [SRC[>>14, >>23]]。ここで終わります。
== [21] [[要求]]に [CODE(HTTP)@en[[[Authorization:]]]] [[ヘッダー]]があって
[[応答]]の [CODE(HTTP)@en[[[Cache-Control:]]]] [[ヘッダー]]に
[CODE(HTTP)@en[[[must-revalidate]]]] [[キャッシュ指示子]]がなければ、
蓄積できません [SRC[>>14, >>23]]。ここで終わります。
= [35] [[応答]]が [CODE(HTTP)@en[[[Expires:]]]] [[ヘッダー]]を持つなら、蓄積できます
[SRC[>>14]]。ここで終わります。
= [24] [[応答]]の [CODE(HTTP)@en[[[Cache-Control:]]]] [[ヘッダー]]が
[CODE(HTTP)@en[[[max-age]]]] か [CODE(HTTP)@en[[[public]]]]
の[[キャッシュ指示子]]を持つなら、蓄積できます [SRC[>>14]]。ここで終わります。
= [25] [[応答]]が[[キャッシュ可能]]な[[状態符号]]を持つなら、蓄積できます [SRC[>>14]]。
ここで終わります。
= [31] 蓄積できません。
]FIG]
;; [32] これらの条件は、新たな[[キャッシュ指示子]]により上書きできます [SRC[>>14]]。
[33] ここで「理解」とは、認識しすべての[[キャッシュ]]に関係する動作を実装していることをいいます
[SRC[>>14]]。
;; [43] これは[[蓄積]]して良い条件であり、しなければならないわけではありません。
[[キャッシュ]]はより限定された条件でのみ[[蓄積]]して構いません。
[EG[
[44] 例えば[[キャッシュ]]はより簡易的に実装するために
[CODE(HTTP)@en[[[Cache-Control:]] [[no-cache]]]] の[[応答]]を一切[[蓄積]]しないことにしても構いません。
(>>40 の[[検証]]の実装を省けます。)
]EG]
* キャッシュの再利用
[28] [[キャッシュ]]は、次の条件をすべて満たす時に、
[[要求]]に対して[[キャッシュ項目]]の[[応答]]を再利用できます
[SRC[>>27]]。
[FIG(list)[
- [29] [[実効要求URL]]が一致すること
- [30] [[蓄積]]されている[[応答]]の[[要求メソッド]]が当該[[要求]]に再利用してよいこと
- [36] [CODE(HTTP)@en[[[Vary:]]]] の[[ヘッダー]]が一致すること
- [37] 当該[[要求]]に [CODE(HTTP)@en[[[Cache-Control:]] [[no-cache]]]]
や [CODE(HTTP)@en[[[Pragma:]] [[no-cache]]]] が含まれていないこと
-- [38] ただし[[蓄積]]された[[応答]]の[[検証]]に成功した場合を除く
- [39] [[蓄積]]されている[[応答]]に [CODE(HTTP)@en[[[Cache-Control:]] [[no-cache]]]]
が含まれていないこと
-- [40] ただし[[蓄積]]された[[応答]]の[[検証]]に成功した場合を除く
- [41] [[蓄積]]されている[[応答]]が[[新鮮]]、[[腐敗]]していても提供することが認められている、
[[検証]]に成功したのいずれかであること
]FIG]
[FIG(corollary)[
[47] [[安全]]でない[[メソッド]]の[[要求]]に[[キャッシュ]]が返答することはできず、
[[上流]]に[[転送]]しなければなりません。
]FIG]
;; [45] これらの条件は、新たな[[キャッシュ指示子]]により上書きできます [SRC[>>27]]。
[48] 候補が複数ある時は、最も新しいもの ([CODE(HTTP)@en[[[Date:]]]]
が最新のもの) を使わなければ[['''なりません''']]。
[CODE(HTTP)@en[[[Cache-Control:]] [[max-age]]=0]] または
[CODE(HTTP)@en[[[Cache-Control:]] [[no-cache]]]] をつけて[[転送]]しても構いません。 [SRC[>>27]]
[49] [[時計]]を持たない[[キャッシュ]]は、毎回[[検証]]しなければ[[蓄積]]された[[応答]]を使っては[['''なりません''']]
[SRC[>>27]]。
;; [42] これは再利用して良い条件であり、しなければならないわけではありません。
[[キャッシュ]]はより限定された条件でのみ再利用しても構いません。
;; [46] 再利用については [CODE(HTTP)@en[[[Age:]]]] も参照。
* 歴史
[2] [[RFC 2068]] は [DFN[[[cachable]]]] と綴っていましたが、
[[RFC 2616]] 以降は [DFN[[[cacheable]]]] とされています。
[FIG(quote)[
[FIGCAPTION[
[1] [[HTTP]] ([[RFC 2068]] 1.3, [[RFC 2616]] 1.3)
]FIGCAPTION]
>
:cach[INS[e]]able: A response is cach[INS[e]]able if a cache is allowed to store a copy of
the response message for use in answering subsequent requests. The
rules for determining the cach[INS[e]]ability of HTTP responses are
defined in section 13. Even if a resource is cach[INS[e]]able, there may
be additional constraints on whether a cache can use the cached
copy for a particular request.
:キャッシュ可能:[[応答]]は、[[キャッシュ]]が以後の[[要求]]に回答するのに使うためにその応答メッセージの複製を蓄積することが許されているなら、
[DFN[キャッシュ可能]]です。 HTTP 応答のキャッシュ可能性を決定する規則は13章で定義されています。
応答がキャッシュ可能であっても、特定の要求にキャッシュされた複製を使うことができるかどうかには更なる制約があるかもしれません。
]FIG]