How does HTTP caching work for APIs, and what role do Cache-Control directives play?
Last updated
Caching has two phases. A fresh copy is served with no network call. A stale copy is revalidated via
ETag/If-None-MatchorLast-Modified, often yielding a cheap304.Cache-Controlsets the rules:max-age(freshness lifetime),public/private(shared vs client-only),no-cache/no-store, andmust-revalidate.For APIs, cache mainly
GETresponses, not mutations. UseVary(e.g. onAcceptor auth) so caches don't serve the wrong representation.