Eviction Policy Fundamentals: Why Pure LRU and LFU Are Rarely Enough
The Multi Factor Decision
Eviction must balance: recency (recently accessed items likely reused), frequency (often accessed items valuable), size (1MB consumes 100x space of 10KB), and miss penalty (fetch cost varies). Pure LRU considers only recency; pure LFU only frequency. Real workloads require balancing all four.
Three Layered Architecture
Effective caching combines three layers. Admission decides whether to cache at all, filtering one hit wonders (items accessed once then never again). Eviction chooses which resident to remove. TTL (Time To Live) expiration handles staleness regardless of capacity. Example: TinyLFU admission filters scans, segmented LRU for eviction, TTL for freshness.
Production Constraints
Operations must run O(1). Metadata overhead 24-50 bytes/entry; 10M entries at 50 bytes = 500MB bookkeeping. Lock contention minimized via sharding. At 100,000 QPS with 10ms miss penalty, reducing miss rate from 20% to 16% saves 4,000 backend requests per second.