Course contentsShow
← System Design
Lesson 153 of 1,9194. Caching StrategiesFree lesson

Choosing an Eviction Policy

Matching policy to workload characteristics: LRU for temporal locality, LFU for skewed access, TTL for freshness.

Choosing an Eviction Policy

What you'll learn: How to select the right cache eviction policy by matching it to your workload's access patterns.

The Core Idea

Not all workloads access data the same way. Some applications repeatedly access recent items, others have a few "hot" items accessed constantly, and some need guaranteed freshness. Choosing an eviction policy means matching the policy's strengths to how your application actually uses the cache.

Matching Policy to Workload

LRU for Temporal Locality

If your workload exhibits temporal locality—where recently accessed items are likely to be accessed again soon—LRU (Least Recently Used) is your best bet. Think of a news website where today's articles get repeated views throughout the day.

LFU for Skewed Access Patterns

When you have skewed access patterns—a small set of items accessed far more often than others—LFU (Least Frequently Used) shines. Imagine a product catalog where 10% of products generate 90% of traffic. LFU keeps those popular items cached regardless of when they were last accessed.

TTL for Freshness Requirements

If your data has freshness requirements or natural expiration, TTL (Time-To-Live) ensures stale data doesn't linger. Financial data, session tokens, or weather forecasts need to expire after a certain time, regardless of popularity or recency.

Making the Choice

Consider your workload characteristics:

  • Recency matters most? → LRU
  • Popularity matters most? → LFU
  • Age/freshness matters most? → TTL
  • No clear pattern? → FIFO or Random (simpler, often "good enough")

You can also combine policies—for example, LRU with TTL expiration for both recency optimization and freshness guarantees.

Key Takeaway: Match your eviction policy to your workload's dominant access pattern—LRU for temporal locality, LFU for skewed popularity, and TTL when data freshness is critical.