Card 11/ 11
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-agesets freshness;privatekeeps a response out of shared caches;no-storekeeps it out of every cache.no-cachestores and revalidates; it is notno-store.- ETag is a version label;
If-None-Matchuses weak comparison,If-Matchstrong. - A conditional GET that finds nothing changed gets 304 with no body.
Varyadds 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.
| Header | Sent by | Tells |
|---|---|---|
| Cache-Control | Server | Who may store the response and for how long |
| ETag | Server | The version of this representation |
| Last-Modified | Server | When it last changed |
| Vary | Server | Which request headers change the response |
| If-None-Match | Client | Send the body only if the version differs; 304 otherwise |
| If-Match | Client | Apply this write only if the version still matches; 412 otherwise |
← → move through sections and cards