Card 11/ 11

RecapDifficulty: Advanced1 min

Recap: HTTP Caching and Conditional Requests

Cache-Control says who may keep a copy, and a validator lets client and server agree whether it is still current.

Caching headers decide where copies live; validators decide whether they are current.

  • Private caches serve one user, shared caches serve everyone; a fresh copy saves the trip.
  • max-age sets freshness; private keeps a response out of shared caches; no-store keeps it out of every cache.
  • no-cache stores and revalidates; it is not no-store.
  • ETag is a version label; If-None-Match uses weak comparison, If-Match strong.
  • A conditional GET that finds nothing changed gets 304 with no body.
  • Vary adds request headers to the cache key.
  • A lost update is prevented with If-Match, 412 on a mismatch and 428 when the header is missing.
  • Personal data in a shared cache is a breach; default to private.
Each header, and what it tells a cache or a server
HeaderSent byTells
Cache-ControlServerWho may store the response and for how long
ETagServerThe version of this representation
Last-ModifiedServerWhen it last changed
VaryServerWhich request headers change the response
If-None-MatchClientSend the body only if the version differs; 304 otherwise
If-MatchClientApply this write only if the version still matches; 412 otherwise