Skip to content

DeploymentInteractive lab

Cache eviction simulator

Run the same access trace through LRU, LFU and FIFO

One workload, three eviction policies, one hit-rate chart. Includes the scan pattern that makes LRU look foolish and the skewed one that makes LFU look brilliant.

What this teaches

  • Eviction policies
  • Hit rate vs cache size
  • Scan resistance

The workload

4,000 accesses

A small working set, interrupted by a long sequential sweep through cold keys.

Hit rate, same trace

counted, not modelled
28.1%
LRU
28.1%
FIFO
43.0%
LFU
49.0%
OPT (ceiling)

On the Scan (hot set + sweep) workload at cache size 32, the best online policy is LFU at 43.0 percent, against an optimal ceiling of 49.0 percent.

OPT is not a policy you can deploy - it evicts whichever key is needed furthest in the future, which requires the future. It is here as the ceiling: the gap between LFU at 43.0% and OPT at 49.0% is how much is left on the table by not knowing what comes next, and an online policy anywhere near it is doing well.

Hit rate against cache size

every point is a full re-run
  • LRU
  • FIFO
  • LFU
  • OPT
Hit rate by cache size for each policy on the Scan (hot set + sweep) workload.
Cache sizeLRUFIFOLFUOPT
24.2%4.2%4.5%9.8%
47.8%7.7%8.6%18.1%
814.9%15.3%17.3%27.7%
1220.5%20.6%25.1%34.2%
1625.9%26.4%33.2%38.4%
2427.9%27.9%41.6%44.0%
3228.1%28.1%43.0%49.0%
4828.1%28.1%43.0%58.3%
6432.0%33.1%50.6%67.3%
9652.8%53.8%74.0%82.3%
12878.6%72.8%84.7%90.0%

The first 60 accesses

H is a hit, a gap is a miss
LRU25/60
FIFO25/60
LFU25/60
OPT25/60

Watch the sweep arrive: LRU and FIFO both fill with keys they will never see again and the strip goes dark for a stretch, while LFU keeps the hot set because a single access never outranks a key seen fifty times.

What is real here, and what is standing in

Real: all four policies are genuine implementations, not models of themselves, and every rate on this page is a count of hits over a count of accesses. LRU really is an LRU, FIFO differs from it by exactly the one line that does not reorder on a hit, and OPT really does look ahead through the whole trace.

Standing in: the trace is synthetic, produced by a seeded generator in this tab, and not a production log. Every object costs exactly one slot, where a real cache has variable object sizes, TTLs, sharding, and admission control - and admission control is precisely how a modern cache such as W-TinyLFU gets scan resistance without giving up on recency, which is the thing this page shows LRU lacking and offers no fix for. LFU here never ages its counters, which is why it looks so strong on the skewed workload and would ossify in production around whatever was hot last month.

Everything on this page runs in your browser. Nothing you type is sent anywhere, there is no account, and it keeps working offline.