Caching, and why users see old content
Caches live in more places than you think, and each one can be the liar.
A cache keeps a copy of something expensive so you do not have to fetch or compute it again. Caching is the single most effective performance tool available, and the source of the most maddening bugs, for the same reason: a copy can be out of date.
- The browser
Keeps files and sometimes whole responses. A hard refresh bypasses it. - The CDN
Copies at locations worldwide. Needs an explicit purge. - Your server
Rendered pages or query results held in memory or a shared cache. - The database
Its own internal caches, usually the one you can ignore.
Two strategies cover most needs. Time-based expiry says "keep this for five minutes": simple, and you accept up to five minutes of staleness. Invalidation says "keep this until I tell you otherwise": always fresh, but now you own the job of remembering every place a copy might exist when the underlying thing changes.
How stale is this allowed to be?
A marketing page can be an hour old. An account balance cannot be a second old. Answering this per piece of data is the whole design, and there is no global right answer.
What to remember
- Copies exist in the browser, the CDN, and your server.
- Expiry is simple and slightly stale; invalidation is fresh and your responsibility.
- Content-based filenames sidestep invalidation completely.
Terms in this lesson
Show field notes toggles a search param the loader reads. With it off, the slow promise is never created, so nothing streams.