Cache Eviction Policies 00:00:01 Three shelves and a recency list A librarian has three slots for frequently requested pages. Every hit changes the recency order under exact least-recently-used eviction. Track which page moves without loading another copy. 3 places. The requests are A B C A A D A E A B. A is not here, and there is a free place. C is not here, and there is a free place. A is here. Its last use moves to now. The cache is full. B leaves (last used at time 2, the longest ago) and D takes its place. The cache is full. D leaves (last used at time 6, the longest ago) and B takes its place. A page evicted from this bounded cache can still exist in the source. Recency is evidence about future reuse, not proof that a page has stopped mattering. 00:01:08 Count visits instead of remembering only the last one Keep three slots but use the frequency counter for each resident page. A recently quiet page with many past visits can now outlast a page read just once. 3 places. The requests are A A B B C D A B E A B. A is here. Its count goes up by one. B is here. Its count goes up by one. The cache is full. C leaves (1 use, the fewest) and D takes its place. Request 8: B, hit. B is here. Its count goes up by one. B is here. Its count goes up by one. Define tie breaking and any aging rule. Without aging, an old burst of attention can keep an entry protected long after the workload has changed. 00:02:10 The oldest arrival keeps its place in line Run the same short request trace with first-in, first-out eviction. A repeated hit changes neither insertion time nor the queue order. Predict what leaves on the next miss. 3 places. The requests are A B C A A D A E A B. B is not here, and there is a free place. A is here. Nothing changes: FIFO ignores reads. The cache is full. A leaves (stored at time 1, the first in) and D takes its place. The cache is full. C leaves (stored at time 3, the first in) and E takes its place. The cache is full. D leaves (stored at time 6, the first in) and B takes its place. Compare both policies on the identical sequence. Counting hits alone without the actual trace can conceal why a seemingly popular item was evicted. 00:03:19 Evict the entry nearest expiry Some objects have a short remaining usable lifetime while others will remain eligible much longer. Under the illustrated policy, choose the resident whose deadline is nearest when space is needed. 3 places. The requests are A B C A D E. Request 1: A, miss. A is not here, and there is a free place. Request 2: B, miss. B is not here, and there is a free place. A is here. Here a read renews the time to live. The cache is full. C leaves (expires at time 7, the soonest) and D takes its place. The cache is full. B leaves (expires at time 12, the soonest) and E takes its place. A short remaining lifetime and a low future retrieval cost are different signals. Decide which signal is worth tracking for the application's bounded memory. 00:04:26 Sample instead of maintaining perfect order An exact ordering can be expensive to maintain under many concurrent hits. Pick a small candidate sample and compare its coldest member with the true oldest resident. The cache is full. True LRU would have to know that K4 is the oldest of all. Pick three keys at random: K2, K5 and K6. Only these are compared. K6 has been idle for 300 seconds and leaves. K4 was older, but K6 was cold too. A bigger sample would be closer to true LRU. Approximate selection trades exact eviction order for less bookkeeping. Measure memory, hit rate and origin work on the librarian's actual access distribution before choosing the policy.