Cache-Controlヘッダ

Cache-Controlヘッダについて、理解があやふやだったのでstudyinghttpとRFCを読んでまとめてみる。

http://www.studyinghttp.net/header http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3

HTTP 1.0と1.1

HTTP/1.0ではCache-Controlは実装してない可能性高いので、HTTP/1.0ではPragmaを使うべし。

プライオリティ

キャッシュに対して、その振る舞いを決定するための指示子を記述します。 Cache-Control に含まれる指示子は、Expires や Pragma に優先します。

http://www.studyinghttp.net/header#Cache-Control

By default, a response is cacheable if the requirements of the request method, request header fields, and the response status indicate that it is cacheable. Section 13.4 summarizes these defaults for cacheability. The following Cache-Control response directives allow an origin server to override the default cacheability of a response:

public private no-cache

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1

Cache-Control: max-age

The expiration time of an entity MAY be specified by the origin server using the Expires header (see section 14.21). Alternatively, it MAY be specified using the max-age directive in a response. When the max-age cache-control directive is present in a cached response, the response is stale if its current age is greater than the age value given (in seconds) at the time of a new request for that resource. The max-age directive on a response implies that the response is cacheable (i.e., "public") unless some other, more restrictive cache directive is also present. If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires header is more restrictive. This rule allows an origin server to provide, for a given response, a longer expiration time to an HTTP/1.1 (or later) cache than to an HTTP/1.0 cache. This might be useful if certain HTTP/1.0 caches improperly calculate ages or expiration times, perhaps due to desynchronized clocks.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3

プライオリティに書いたことと同じだが、Cache-Control: max-ageはExpiresヘッダの設定に優先する。