Every modern computer carries a private lie: the memory your program thinks it has is much slower than the memory it actually uses. Between the CPU and the sprawling depths of RAM sits a cache — a small, blazingly fast pool of data that your processor checks first. If the data is there (cache hit), you're done in nanoseconds. If it isn't (cache miss), you wait a hundred times longer while the system fetches it from slower storage.
Caches are useful precisely because programs are not random. They tend to touch the same data again and again — a phenomenon called locality of reference. A cache that holds the "right" data sees mostly hits; one that holds the wrong data constantly misses and might as well not exist.
The catch is that caches are small. The moment you try to bring in one more item and the cache is full, something has to leave. The rule that decides what gets evicted is the eviction policy — and it is one of the most consequential small decisions in all of systems design.
The four classic policies are LRU (Least Recently Used), LFU (Least Frequently Used), CLOCK (an efficient approximation of LRU), and ARC (Adaptive Replacement Cache). Each bets on a different model of the future: that what you used last is what you'll use next, or that what you've used most often will keep being popular, or that you need both kinds of prediction at once.
Comments
Loading comments...