A cache eviction policy is the algorithmic logic that selects which entry to remove when a cache reaches its maximum allocated capacity and a new item must be inserted. The policy's objective is to maximize the cache hit ratio by retaining data most likely to be requested again. Common strategies include LRU (Least Recently Used), which discards the stalest access, and TTL (Time-To-Live) expiration, which removes entries based on absolute age rather than access frequency.
Glossary
Cache Eviction Policy

What is Cache Eviction Policy?
The deterministic algorithm governing which stored objects are purged from a saturated cache to accommodate new data, directly impacting hit ratios and retrieval latency.
The choice of policy critically shapes P99 tail latency in retrieval pipelines. An optimal policy exploits temporal locality, keeping hot embeddings or query results in fast memory while evicting cold data. In semantic caching systems, eviction may also consider the computational cost of regeneration; a complex summarization result might be retained longer than a cheaply computed embedding, prioritizing the prevention of expensive recomputation over simple data volume.
Core Eviction Strategies
The algorithmic logic that governs which data is purged when a cache reaches capacity. Selecting the right eviction policy directly impacts cache hit ratio, tail latency, and the overall effectiveness of your retrieval pipeline.
Least Recently Used (LRU)
The foundational temporal eviction algorithm that discards the item with the oldest access timestamp first. LRU operates on the principle of temporal locality: data accessed recently is highly likely to be accessed again soon.
- Mechanism: Maintains a doubly-linked list and hash map. Every
GETorSETmoves the item to the head. Eviction removes from the tail. - Complexity: O(1) for both access and eviction.
- Best For: General-purpose workloads with strong recency bias, such as user session data or recent document queries.
- Weakness: Vulnerable to cache pollution from a full scan of infrequently accessed data, which flushes out the genuinely hot working set.
Time-to-Live (TTL) Expiration
A time-bound eviction policy where each cache entry is assigned an absolute or sliding expiration timestamp upon insertion. The entry is automatically invalidated and removed once its lifespan elapses, regardless of access frequency.
- Absolute TTL: Expires at a fixed wall-clock time (e.g., '2025-01-01 00:00:00 UTC'). Ideal for daily financial snapshots.
- Sliding TTL: Resets the timer on every access. Ideal for user sessions where idle timeout is the concern.
- Best For: Data with known staleness windows, such as embedding caches for semi-static documents or API rate-limit counters.
- Weakness: Does not react to memory pressure. A sudden write spike can fill the cache with unexpired entries, causing an out-of-memory error before the timer fires.
Least Frequently Used (LFU)
An access-count-based policy that evicts the item with the lowest hit frequency. LFU tracks a counter for every key and removes the statistically least popular item when capacity is reached.
- Mechanism: Often implemented with a min-heap or a frequency list. A
GETincrements the counter and re-orders the item. - Best For: Stable, long-lived datasets where historical popularity is a strong predictor of future value, such as a semantic cache storing frequently asked enterprise questions.
- Weakness: Cache pollution from historical data. An item that was extremely popular last week but is now irrelevant retains a high count and refuses to be evicted, occupying space that new, relevant data needs. Modern variants like Window-TinyLFU add recency weighting to solve this.
First-In, First-Out (FIFO)
The simplest eviction policy, operating as a standard queue. The first item written into the cache is the first item evicted, regardless of how many times it has been accessed since insertion.
- Mechanism: A simple queue data structure. No re-ordering on access.
- Complexity: O(1) for all operations. Extremely low CPU overhead.
- Best For: Write-heavy, transient data streams where no single item is more valuable than another, such as a KV-Cache for a continuous batching inference server where sequences are processed in strict generation order.
- Weakness: Completely ignores access patterns. A frequently accessed 'hot' item will be evicted simply because it was the first to arrive, drastically reducing hit ratio for read-heavy workloads.
Random Replacement (RR)
A probabilistic eviction strategy that selects a random candidate for removal when the cache is full. Despite its simplicity, it performs surprisingly well in specific adversarial scenarios.
- Mechanism: A random number generator selects the victim index. No metadata tracking is required.
- Best For: Extremely high-throughput systems where the overhead of tracking access order or frequency is prohibitive, or as a baseline comparison for more complex policies.
- Advantage: Immune to cache stampede pathologies caused by synchronized expiry timers. It naturally distributes eviction pressure.
- Weakness: Non-deterministic performance. It can occasionally evict the single most valuable item in the cache, causing a temporary latency spike for that specific query.
Segmented LRU (SLRU)
A hybrid policy that splits the cache into a probationary segment and a protected segment. New entries enter probation; if accessed again, they are promoted to the protected segment. Eviction occurs from the probationary end.
- Mechanism: Two LRU lists. A hit in probation promotes the item to the protected segment's head. When the protected segment is full, its tail item is demoted back to probation.
- Best For: Workloads susceptible to cache pollution from sequential scans. A single linear scan of a database table will cycle through the probationary segment without flushing the protected 'hot' set.
- Real-World Use: Forms the basis of many high-performance in-memory databases and OS page replacement algorithms. It provides a strong balance between recency and frequency without the historical baggage of pure LFU.
Frequently Asked Questions
A cache eviction policy is the algorithmic logic that determines which data to purge when a cache reaches its capacity limit. Understanding these policies is critical for infrastructure engineers optimizing retrieval latency and maintaining high cache hit ratios in answer engine architectures.
A cache eviction policy is a deterministic algorithm that selects which entries to remove from a full cache to accommodate new data. When a cache—such as Redis, Memcached, or an in-memory hash table—reaches its allocated memory threshold, the eviction policy triggers to free space. The policy evaluates all cached entries against a specific criterion: recency of access, frequency of use, explicit time-to-live (TTL) expiration, or a cost function. The selected entry is then invalidated and removed. The choice of policy directly impacts the cache hit ratio, which is the percentage of requests served from cache rather than the slower backend. Common implementations include LRU (Least Recently Used), LFU (Least Frequently Used), FIFO (First-In, First-Out), and TTL-based expiration. In distributed answer engines, eviction policies must also account for cache coherence across nodes to prevent serving stale data.
Comparison of Common Eviction Policies
A technical comparison of the primary algorithms used to determine which entries to discard when a cache reaches capacity, evaluated against key operational metrics for retrieval pipelines.
| Feature | LRU (Least Recently Used) | LFU (Least Frequently Used) | TTL (Time-to-Live) | FIFO (First-In, First-Out) |
|---|---|---|---|---|
Core Mechanism | Tracks last access timestamp; evicts the stalest entry | Tracks access frequency counter; evicts the least popular entry | Assigns an absolute expiration timestamp per entry; evicts on expiry | Maintains a queue ordered by insertion time; evicts the oldest entry |
Optimal Workload | Temporal locality (recently accessed items likely re-accessed) | Popularity-based workloads with stable hot-item sets | Data with known, deterministic freshness requirements | Streaming or batch-processing workloads with no re-access patterns |
Memory Overhead | Low (doubly-linked list + hash map) | Medium (heap or sorted structure for frequency counts) | Low (per-entry timestamp only) | Minimal (single queue pointer per entry) |
Resistance to Cache Pollution | Moderate (a single scan can flush working set) | High (requires sustained frequency to remain; protects hot items) | High (pollution limited to entry's lifespan) | Low (scan-resistant; sequential reads flush entire cache) |
Implementation Complexity | Low | Medium | Low | Very Low |
Adapts to Access Pattern Shifts | ||||
Suitable for Semantic Cache | ||||
Typical P99 Latency Impact | < 1 ms (in-memory) | < 2 ms (heap maintenance) | < 0.5 ms (passive expiry check) | < 0.5 ms (pointer shift) |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Mastering cache eviction requires understanding the performance metrics, alternative caching strategies, and failure modes that dictate system design.
Cache Hit Ratio
The primary metric for evaluating an eviction policy's effectiveness. It represents the percentage of requests served from the cache.
- Formula:
(Cache Hits / Total Requests) * 100 - A high hit ratio means the eviction policy is correctly predicting future access patterns.
- Example: A 95% hit ratio means only 5% of requests incur the high latency of a primary database lookup.
Semantic Cache
A caching layer that stores query-answer pairs based on semantic similarity rather than exact string matching.
- Uses vector embeddings to determine if a new query is sufficiently similar to a cached query.
- Benefit: Can serve a cached response for a paraphrased question, dramatically increasing the effective hit ratio for natural language systems.
- Eviction Policy: Often uses a similarity threshold combined with TTL, as traditional recency-based policies don't map cleanly to semantic space.
Cache Stampede
A catastrophic failure mode that occurs when a highly popular cache entry expires.
- Scenario: A hot item expires. A flood of concurrent requests simultaneously miss the cache and hammer the backend database.
- Mitigation: Use probabilistic early expiration or a locking mechanism so only one request is allowed to regenerate the value.
- This is a critical consideration when setting TTL-based eviction policies for high-traffic keys.
TTL-Based Expiration
A Time-To-Live policy evicts items after a fixed duration, regardless of access frequency.
- Use Case: Ideal for data with a known staleness window, like session tokens or weather data.
- Contrast with LRU: TTL guarantees data freshness; LRU optimizes for access patterns.
- Implementation: Can be passive (evict on access) or active (a background sweeper process removes expired keys).
KV-Cache
A specialized memory mechanism in transformer models that stores the computed Key and Value tensors from previous tokens.
- Function: Prevents redundant computation during autoregressive text generation.
- Eviction Policy: Uses a sliding window or token budgeting. When the context window is full, old KV pairs are evicted, often using a simple FIFO or a more complex priority policy to retain important tokens.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us