Caching
Cache-Control: multiple-choice review
Six questions across the whole unit. Each maps to a header you would actually ship — and to the silent incident that follows when a directive does something other than what its name suggests.
Confirm you can pick the right directive for storage vs revalidation, separate browser TTLs from CDN TTLs, and reason about the leaks and traps that the defaults set up.
A team ships Cache-Control: no-cache on a bank-balance endpoint, intending that nothing is ever stored. A kiosk later shows one customer the previous customer's balance on a back-button press. What went wrong?
You set Cache-Control: max-age=0 on your HTML to keep browsers always fresh. A CDN sits in front. With no s-maxage, what happens at the CDN?
An authenticated /account route is served with Cache-Control: public, max-age=300 behind a CDN. Every visitor for the next five minutes sees the first user's account page. The root cause?
Static bundles are served with Cache-Control: public, max-age=31536000, immutable. What single practice makes a one-year cache safe rather than a one-year bug?
A CDN-fronted JSON API ships Cache-Control: max-age=60, s-maxage=300, stale-while-revalidate=3600. What is the resulting behaviour?
A response sets Vary: Cookie to keep a logged-in page off shared caches. Why is this an unreliable safety mechanism for per-user content?
The unit’s through-line is one decision tree. First ask whether a cache may store the response at all: no-store is the only directive that forbids storage, and no-cache merely forces revalidation, which is why no-cache leaks sensitive data into the browser and bfcache. Then separate the tiers: max-age governs every cache, s-maxage overrides it for shared caches only, and private keeps per-user responses off the CDN — its absence on an authenticated route is the classic data-leak. For static assets, public, max-age=31536000, immutable is correct only with content-hashed filenames, because a changed file then changes the URL. stale-while-revalidate and stale-if-error trade staleness for latency and resilience, and Vary keys variants rather than excluding sharing — so the real safety always lives in private/no-store.