Layers of Caching
From browser to database.
Caching doesn't happen in just one place. A single page view can pass through five different caches, from the user's own browser all the way down to the database.

- Not just one place
- Five layers
- Browser to database
The caching layers
Starting closest to the user. The browser cache keeps files on the user's device. The CDN caches at edge servers nearby. The application can cache in its own memory. A shared cache, like Redis, serves all app servers. And the database has its own cache of recently used data.
- Database cacherecent pages of data
- Shared cacheRedis, all servers
- App memoryinside each server
- CDNedge servers
- Browseron the user's device
Using the layers well
The closer the cache is to the user, the faster it is, but the harder it is to clear. Browser caches can't be cleared by you at all, so files get version numbers in their names. Shared caches are easy to clear. Choose the layer based on how fresh the data must be.
| key | value |
|---|---|
| Closer | faster |
| Closer | harder to clear |
| Browser files | version the names |
| Shared cache | easy to clear |
Summary
Caches live in the browser, the CDN, the app, a shared store, and the database. Closer is faster, but harder to clear. Next, a quiz on caching.
Key takeaways- Browser, CDN
- App, Redis
- Database cache