HTTP - Cache (Cache-Control Header, Bursting, ...)

> (World Wide) Web - (W3|WWW) > (HTTP|HTTPS) - Hypertext Transfer Protocol

1 - About

Cache layer in HTTP


3 - Control

3.1 - Headers

The Cache-Control headers (introduced in the HTTP 1.1 specification) cover browser caches and in most cases, intermediate caches as well:

  • Cache-Control: public - Any cache can store a copy of the content.
  • Cache-Control: private - Don't store, this is for a single user.
  • Cache-Control: no-cache - Re-validate before serving this content.
  • Cache-Control: no-store - Don't ever store this content.
  • Cache-Control: public, max-age=[seconds] - Caches can store this content for n seconds.
  • Cache-Control: s-maxage=[seconds] - Same as max-age but applies specifically to proxy caches.

Only the max-age, s-maxage, and private Cache-Control headers will influence proxy caching

3.2 - Bursting

Cache bursting: Files may be cached by the browser/proxy for a certain period of time. When releasing a new version, the HTML may be then not in sync because the browser (of any cache system in-between) will keep serving the old one without download the old one. One solution for this kind of problem is Web HTTP - Cache Bursting

4 - Property

4.1 - Status Code

The cache is a redirection to a cached resource.


4.2 - Key

The primary cache key consists of:

However, since HTTP caches in common use today are typically limited to caching responses to GET, many caches simply decline other methods and use only the URI as the primary cache key.

5 - How

5.1 - Apache htaccess configuration

If the mod_header is present, Apache can send the caching header.

Example in the root htaccess, max age is in second

# Cache File
<IfModule mod_headers.c>
    # WEEK
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
        Header set Cache-Control "max-age=604800, public"
    # WEEK
    <FilesMatch "\.(js|css|swf)$">
        Header set Cache-Control "max-age=604800"

6 - Specification

  • Hypertext Transfer Protocol (HTTP/1.1): Caching (rfc7234), R. Fielding, M. Nottingham, J. Reschke. IETF.

7 - Documentation / Reference