policybook / cache

cache

Policies for deciding which key to drop when a cache is full. A cache holds at most `capacity` keys, so when a new one arrives something has to go, and which one is the whole question. The difference between a good and a bad eviction rule on the same workload is routinely ten points of hit rate, for identical memory and near-identical cost per operation.

Run these side by side → Same trace, same seed, stepped in lockstep.

Choosing one

If you needUseBecause

One good default

SIEVE

Scan-resistant, no lock on a hit, and the simplest thing here that is genuinely good.

The highest hit rate

W-TinyLFU

A frequency sketch turns admission into a contest the incumbent usually deserves to win.

Web or CDN traffic full of one-hit wonders

S3-FIFO

Most objects die in a small probation queue without ever touching the main cache.

To survive workload shifts without retuning

ARC

Adapts its own recency/frequency split as the workload moves, but check the patent history.

Scan resistance you can explain in a sentence

2Q

A key must come back after eviction to earn the main cache.

LRU without a write on every hit

CLOCK

One reference bit and a sweeping hand approximate the same order.

The default nobody will question

LRU

The baseline everything else here is measured against, and a scan flushes it.

Stable popularity, with scans passing through

LFU

Ranks by lifetime frequency. The price is that it cannot forget.

Predictable eviction, or hits that cost nothing

FIFO

Ignores reuse entirely. It is the floor everything else must beat.

Benchmarks

Hit rate on each trace, measured by this repository's benchmarks.

Policy zipf-1.0-100k zipf-0.75-1m scan-heavy shifting-popularity
W-TinyLFU 0.73390.49710.67460.6597
S3-FIFO 0.73000.48560.67340.6849
LFU 0.72730.47680.66860.3229
SIEVE 0.72730.47680.66860.6101
ARC 0.72480.47530.66870.6887
2Q 0.71470.46500.65870.6792
CLOCK 0.68500.41450.62220.6748
LRU 0.67460.40230.61390.6665
FIFO 0.63060.36550.57630.6261
Bélády OPT reference 0.80870.63990.74730.7939

Every policy