Track 2 · Building Blocks
Caching Strategies
A cache is a bet that the same question will be asked again. This page covers where to put the cache, how reads and writes should flow through it, what really happens when a step fails, and how a good cache falls over on the busiest night of the year.
Guide20 min read
On this page
- The 8 PM cliff
- The simple version
- Reading: three ways to fill a cache
- Writing: what happens to the cache when data changes
- The invalidation race in cache-aside
- Expiry and eviction
- When the cache itself becomes the problem
- Code: cache-aside with single flight and a safe lock
- What a cache means for consistency
- Decision table
- Common traps
- Cross-questions