What a cache really caches

hit_rate x saved_trips > miss_cost

A cache stores a past answer and a claim about its freshness, so eviction decides which stale answers survive.

A cache is a bet on reuse. Each hit skips a round trip, a slower tier, or a distance, but every miss pays the lookup and then the original read. The bet pays only when hit rate is high enough, and the eviction policy decides which answers stay, including the ones that have gone stale. A stale hit is a wrong answer delivered with confidence.

A cache entry is a computed answer, not a row. It holds the output of a query or computation, and its validity depends on every input. The key therefore has to name everything the answer depends on. If the answer depends on the user, the key includes the user, or one user's page is served to another. If the answer merges a dozen sources, changing one source must invalidate the entry. On a hit, the application returns the stored answer without asking whether it is still right. On a miss, it reads the backing store, stores the result, and returns it. Each request pays the lookup, so a hit costs the lookup alone, while a miss adds the full backing read on top.

The abstraction hides eviction as a performance detail. Consider a cache with three slots. One user's page is the hottest key, checked every five minutes. Another user's query inserts an entry, and under FIFO the oldest entry gets evicted, which is the hot page, even though it has been read a hundred times. The next check misses, the database answers, and the cycle repeats while entries nobody requests stay in place because they arrived recently. Nothing returns a wrong answer, yet users see random latency. If the evicted entry had been an unflushed write-back, the same policy would have destroyed a write. Hit rate averages over this, so a dashboard can look healthy while one class of key misses every time.

Decide per key class before choosing a policy. For each class, state the stale window you can tolerate and the cost of a miss. Use LRU as the default, but watch for scans, which can flush the working set. Use LFU only when popularity is stable, since it fails when popularity shifts. Use FIFO only when age really is the right proxy for usefulness. Use random when metadata memory is tighter than the cost of a miss. Put a TTL ceiling on any value whose truth can change without a read. Keep write-back entries durable before they become evictable. Make keys complete enough that a hit cannot cross users. Then measure hit rate per class, and compare it against the lookup plus round trip that each miss costs.

orders of magnitude
break-even hit rate
about 90%

Below roughly this hit rate, a cache often costs more than it saves, because each miss pays the lookup and the full backing read.

miss cost
lookup plus one round trip

Every miss adds the cache check to the trip to the source.

LRU weakness
scans

A one-time sweep can push out the working set that gets reused.

LFU weakness
shifting popularity

Frequency counts keep old hot keys alive after demand moves on.

field note

The naive deployment treats a cache as a faster database. Each web server checks the cache, falls through to the database on a miss, and writes the result back. Staging shows healthy hit rates, so nobody measures the tail. The assumption is that a small miss rate means a small cost.

At production scale, the small miss rate stops being small. When a popular key expires, many requests miss at once and race to the database together. That burst saturates the backing store, and the slowest requests set the latency users feel. The memcache paper treats this tail as the cost of miss fan-out, which appears only under load.

The memcache design uses a demand-filled look-aside cache, so the application owns the fill. Leases stop a stale set from overwriting a newer value, and they make concurrent misses wait instead of stampeding the database. The lesson is that a cache is a bet on reuse. Judge it by hit rate against the cost of a miss, and treat the fill policy as part of correctness.