What does stale-while-revalidate do, and what does it cost?
Sketch your own answer first, then compare it with the one below.
A strong answer
It lets a cache answer with an expired copy for a short window after expiry, while it refreshes the copy in the background. Users do not wait for the origin on the request that finds the copy expired.
The cost is that a user may see a copy that is slightly old. The origin load does not fall, because the refresh still happens. What changes is who waits for it.
A related directive, stale-if-error, lets a cache serve an old copy when the origin is failing, which keeps a site up through a short outage.
Sources
- Mark Nottingham (2010). RFC 5861: HTTP Cache-Control Extensions for Stale Content.
- Roy Fielding, Mark Nottingham, Julian Reschke (2022). RFC 9111: HTTP Caching.