Bounding How Stale Data Can Get
A cached value can drift from the truth. A time to live, or TTL, sets how long an entry may be served before it is considered expired and must be refreshed from the source.
The Latency Problem at Expiry
If the cache simply blocks every request when an entry expires, users pay the full origin latency right at that moment. Stale while revalidate softens this: when an entry is expired but still within a grace window, the cache serves the stale value immediately and refreshes it in the background.
The Three Windows
- Fresh means the entry is within its TTL and served directly.
- Stale but revalidating means it is past TTL but inside the grace window, so the old value is served while a refresh runs.
- Hard expired means it is past the grace window, so a request must wait for fresh data.
This trades a little staleness for steady low latency and shields the origin from a thundering rush at the expiry instant.
Key idea
TTL caps staleness, and stale while revalidate serves the old value during a grace window while refreshing in the background to keep latency flat.