Caching at Every Layer
Caching stores the result of an expensive operation so future requests return instantly without repeating the work. It exists at every layer: the browser caches responses via Cache-Control headers, a CDN caches content at edge locations, the application caches database results in Redis, and the database itself caches hot pages in its buffer pool.
The hardest caching problem is invalidation — knowing when to evict stale data. Write-through caches update the cache on every write, staying consistent at the cost of slower writes. Cache-aside is the most common: read from cache, fall through to the database on miss, then populate the cache for next time. Use TTLs as a safety net so stale data cannot live forever even if invalidation logic misses.
Check your understanding
What is cache-aside?Show answerHide answer
Answer
App checks cache, loads DB on miss, then populates the cache — app owns the flow.Why use TTLs even with explicit invalidation?Show answerHide answer
Answer
As a safety net when an invalidation is missed so stale data cannot live forever.Where can caches live?Show answerHide answer
Answer
Browser, CDN, app memory, Redis/Memcached, and DB buffer pools — among others.