Pcornel
Web Infrastructure · HTTP

HTTP Caching

Cheat sheet · https://pcornel.dk/topic.php?topic=6267

Back to the Topic

Answer

HTTP caching lets browsers, proxies and CDNs reuse responses. The origin controls it with Cache-Control, Expires, ETag/Last-Modified and Vary; caches decide freshness and revalidate with conditional requests.

Remember

no-store = never store. no-cache = store but revalidate every time. private = browser only, not shared caches. s-maxage applies to shared caches and wins over max-age there. Vary adds request headers to the cache key. A 304 reuses the stored body.

First checks

  • curl -sSI https://<host>/<asset> — Cache-Control, ETag, Last-Modified, Age, Cache-Status.
  • curl -sSI -H 'If-None-Match: "<etag>"' https://<host>/<asset> — expect 304.
  • nginx: log $upstream_cache_status (HIT, MISS, EXPIRED, STALE, BYPASS, REVALIDATED, UPDATING).

Verify in this order

request → cache key (method + URI + Vary headers) → stored response fresh? → serve with Age : else conditional request (If-None-Match / If-Modified-Since) → 304 reuse or 200 replace

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6267

Confirmation

Confirm action

Continue?