Cache Eviction Policies
Explore how caches decide what to keep and what to discard when memory is full, covering LRU, LFU, FIFO, TTL, and their trade-offs.
Why Eviction Is Necessary
A cache is fast because it lives in limited memory. When it fills up, it must evict something to make room for new data. The eviction policy decides what to drop.
A good policy keeps the data most likely to be reused.
Hit Rate Is the Goal
The metric that matters is the hit rate: the fraction of requests served from cache. A better eviction policy raises the hit rate, which means fewer slow trips to the database or origin.
hits = 850
misses = 150
hit_rate = hits / (hits + misses)
print('hit rate:', hit_rate)All lessons in this course
- Cache Invalidation Patterns
- CDN Integration & Edge Caching
- Distributed Caching with Redis
- Cache Eviction Policies