Eviction Policy
An eviction policy is the rule a cache uses to decide which entry to remove when it reaches its memory limit and needs to make room for a new entry. Choice of policy directly affects hit rate and is one of the most consequential cache configuration decisions.
Common policies
- LRU (Least Recently Used). Evict the entry that has not been accessed for the longest time. Default in many systems; good for workloads with recent-bias.
- LFU (Least Frequently Used). Evict the entry with the lowest access count. Better for workloads where some items are hot regardless of recency.
- FIFO (First In, First Out). Evict the oldest entry by insertion time. Simple, ignores access patterns.
- Random. Evict a random entry. Cheap and surprisingly competitive on some workloads.
- TLRU (Time-aware LRU). LRU with TTL awareness; expired entries are preferred for eviction.
- ARC (Adaptive Replacement Cache). Dynamically balances recency and frequency.
- TinyLFU and W-TinyLFU. Modern, used by Caffeine; uses a frequency sketch to decide admission.
Variants in Redis
Redis exposes the policy via maxmemory-policy: noeviction, allkeys-lru, allkeys-lfu, allkeys-random, volatile-lru, volatile-lfu, volatile-random, volatile-ttl. The volatile-* variants only evict entries that have a TTL set.