LRU is fine until something reads everything once
Most caches run least-recently-used eviction, and usually nobody needs to think about it again. When it goes wrong there is no error, only a graph.
A news site keeps rendered article pages in Redis: about 200,000 of them, roughly 50 KB each, in 10 GB of memory, in front of an archive of 2 million articles. By day, readers make 3,000 page requests a second and 94% are answered from the cache. Every night at 02:00 the hit rate drops to around 60%, and it takes most of the morning to climb back. What runs at 02:00 is the sitemap job, which re-renders every article in the archive through the same code path as a reader.
A cache is a fixed amount of fast memory holding a moving subset of the data. Once it is full, every new entry costs one or more old ones, and the rule that picks the victim is the eviction policy. It matters because most of a cache's value is its hit rate: the right policy keeps the entries most likely to be read again, and the wrong one quietly turns the cache into an expensive no-op. This one ran Redis with allkeys-lru.
What least-recently-used does with a scan
LRU (least recently used) evicts the entry whose last read is the oldest. It bets on temporal locality: what was read a moment ago will be read again soon. For readers that is a good bet. The sitemap job breaks it. It reads 2 million articles in an hour, about 556 a second, almost all of them archive pages nobody asked for that day. Each one misses, is rendered, and enters the cache as the most recently used entry.
In about six minutes the job alone has inserted as many pages as the cache holds. Any page readers did not touch in that time is gone. Not the front page, which is read every second, but the long tail that made up the 94%: yesterday's second-tier stories, explainers read a few times an hour. Their replacements will not be read again. This is scan pollution: one pass over a large dataset evicts the entries that are actually reused, and keeps the ones that are not.
The cheapest fix leaves the policy alone: the job does not need the cache, so let it read the database directly, or have the service skip the cache fill for its requests. When a scan cannot be routed around, pick a policy that does not trust a single read.
The article service looks in the cache and renders from the database on a miss. The sitemap job reads the database without filling the cache, so its one-off reads evict nothing.
Counting reads instead
LFU (least frequently used) evicts the entry read least often. In a plain LFU, a page the job read once has a count of one and loses to anything readers come back to, so a scan barely dents the cache. But a count measures the past. On Monday a story about a storm drew 40 million reads. By Wednesday nobody opens it, and its count still keeps it in memory, while a page published an hour ago starts with the lowest count in the cache and is the next victim whenever memory is tight, before it has had a chance to become popular. A frequency that never decays protects yesterday's news and starves today's.
So practical LFU ages its counts, and real caches approximate both policies rather than tracking them exactly. Redis's LFU keeps a small logarithmic counter per key that falls while the key goes unread (lfu-decay-time), and both its LRU and LFU modes pick a victim by sampling a few keys (maxmemory-samples, 5 by default) instead of keeping a global order. Caffeine, a widely used Java in-process cache, runs W-TinyLFU: a new entry waits in a small LRU window, then enters the main area only if a frequency sketch, a compact table of approximate counts that is halved periodically, says it is read more often than the entry it would replace. That gate is a third lever beside the two policies, admission: refusing to cache one-shot reads at all, the job's archive pages for instance, often beats a cleverer eviction rule.
Time is a different question
Eviction answers "memory is full, what goes?". A TTL (time to live) answers "how old may this copy get?". An article corrected at 09:00 must not keep showing the error until the cache happens to need room, so each page also carries a TTL. Neither stands in for the other. A TTL alone does not bound memory: if entries arrive faster than they expire, the cache still fills, and in the meantime it drops hot entries on a timer while keeping cold ones until they expire. Size-based eviction alone does not bound staleness. So deployments combine a TTL for staleness with LRU or LFU for space: in Redis, an expiry on each key plus the allkeys-lru or allkeys-lfu maxmemory policy, which picks victims among all keys, with or without a TTL.
One TTL for everything is its own mistake. A live blog updated every minute and an explainer from 2019 that never changes have different staleness budgets, and a uniform TTL over-refreshes one and lets the other go stale.
TTLs can also line up: a deploy that warms the 5,000 most-read pages within one minute, all with a one-hour TTL, makes them all expire within one minute an hour later. Adding jitter, a random part such as 3,600 seconds plus or minus 10%, spreads those expiries over about 13 minutes. One key hot enough to hurt by itself is a separate problem, the subject of Hot keys & cache stampedes.
Could you defend each policy?
The 02:00 graph is also how you know a fix worked. Hit rate is the primary score — measure it, alongside staleness and miss cost, before and after any policy change, with evictions per second beside it. The Distributed Cache Challenge spreads one cache over many nodes and asks for LRU and TTL eviction and for hit-rate monitoring. The question to ask of your design there is the one this article asked of the news site: for each kind of data, could you say from the shape of its traffic why it gets that policy, that TTL and that much memory, and is there a metrics node wired to the cache nodes that would tell you if you were wrong?