AlgoViz

Cache eviction policies

easy 22 min

A cache has a memory limit.

Where it shows up

The same pattern appears across everyday software.

  • Redis

    Offers policies over all keys or only keys with a TTL, with approximate LRU and LFU. The operator picks one with `maxmemory-policy`.

  • memcached

    Splits its LRU into hot, warm and cold parts, so an entry must prove itself with a second access before it stays long.

  • Caffeine (Java)

    An in-process cache that uses Window TinyLFU: a small recency window plus a frequency filter for admission.

  • Python's lru_cache

    A decorator that keeps recent results of a function, with an optional size limit. Without a limit it never evicts.

  • CDN edge servers

    An edge server cannot store every file on the internet. Unpopular files leave and are fetched again from the origin.

  • Database buffer pools

    Databases keep pages in memory and evict them too. A full table scan is the classic enemy, so many use scan-resistant variants.