Caching stores the result of expensive work so it can be reused. It is often the cheapest way to make an application faster and to reduce database load. It is also where subtle bugs live: the hard part is not storing data but knowing when it has gone out of date.
Layers of caching
- Browser and CDN caching for static files and public pages
- Application caches, such as Redis, for frequently read data
- Materialised views and summary tables for expensive reports
- In-process caches for small, rarely changing reference data
Choosing what to cache
Good candidates are read often, change rarely and are expensive to compute: product catalogues, configuration, hourly exchange rates, dashboards. Poor candidates are personalised, fast-changing or security-sensitive data, such as account balances or permissions.
Keeping data fresh
Give every cached item an expiry time, even if you also clear it on change. Prefer updating or clearing the cache when the source data changes, and include the tenant and user in cache keys wherever data differs between them. Protect against a stampede when a popular item expires by letting one request refresh it while others wait or receive the previous value.
Our engineers and consultants write about what they see in real projects. Have a question about your own systems?





