liveBook · Manning

Eviction policy

As explained in Fast by Default

An eviction policy defines which retained data or cached entries are removed when a resource bound is reached.

An eviction policy decides which cached or retained entries to remove once a defined resource bound is reached. It keeps memory consumption bounded as datasets, sessions, caches, undo histories, and document state grow over time; without bounds, a system may appear healthy initially and later exhaust memory. section 4.5.3 section 5.2.3

Eviction is one part of a self-correcting retention strategy. Cache only needed data, set size limits, and pair removal rules with expiration and invalidation. Expiration refreshes stale data eventually when explicit invalidation fails, while eviction prevents retained data from growing without limit. section 4.5.3 section 5.2.3

Design eviction around an explicit budget and observable behavior:

  • Set a maximum entry count or size limit for each cache, undo stack, or retained-state structure. section 5.2.3
  • Choose a removal rule that matches use: document caches can evict by last access time, while an LRU cache uses a maximum entry count. section 5.2.3
  • Use TTLs as a consistency backstop for cached data, keeping expiration short enough for an acceptable stale-data window. section 4.5.3
  • Monitor memory over extended, day-long usage and alert on growth patterns that indicate a leak. section 5.2.3

Bounded undo history

A photo editor that retains a full image copy for every edit can consume gigabytes in one session. Give the undo stack a size limit and evict older retained states so undo remains useful without treating memory as unlimited. section 5.2.3

Distributed caches add a separate concern: entries may reside on many nodes, so invalidation can fail unevenly and expose stale and current values simultaneously. Eviction controls capacity, but does not by itself solve consistency; for consistency-sensitive data, bypassing the cache may be the safer choice. section 4.5.3

How Fast by Default covers it

How deep it goes
Gives implementation guidance through size limits, LRU and last-access rules, monitoring, and long-session testing without algorithm internals.
Examples
Uses growing caches, distributed profile invalidation, photo-editor undo copies, and document caches evicted by last access.
What you can do after
Apply it by setting bounded cache and retained-state limits, selecting removal rules, and monitoring memory growth over extended sessions.
How it connects
Connects eviction policies to caching, TTL, cache invalidation, eventual consistency, LRU caches, undo history, and memory monitoring.

Also explained in

Compare how 2 books explain eviction policy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast by Default. The section links point to the parts of the book it draws on.