Interactive explainer · cache eviction policies

Every cache eviction policy is a bet

When a cache is full, something has to go. LRU bets the key touched longest ago is done. LFU bets the least popular one is. Newer designs hedge. Each bet pays off on some traffic and loses on other traffic, and hit ratio is only half the bill. Below, eight policies replay the same request streams, simulated live in this tab.

Workload

No policy wins everywhere

Hit ratio for every policy on every workload, at the cache size chosen above. Color shows the gain or loss against plain LRU. Pick a column to explore that workload below.

Hit ratio by policy and workload

Inside one workload

What the requests look like

Hit ratio as the cache grows

Log scale. Click to set the cache size.

Hit ratio over time

Per 2,000 requests, starting from an empty cache.

Hit ratio is only half the bill

What each policy does on every request decides how it behaves under many threads. A policy that rewrites a shared list on every hit needs a lock on every request. One that only flips a bit or bumps a small counter can serve hits without coordinating. The measured columns come from the same simulation, for the workload and size chosen above.

How each policy decides

What each policy bets on, and where the simulation above shows the bet losing.

How this works