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

