A cache eviction policy is the deterministic algorithm that selects which entry to remove from a full cache to make space for new data. The policy's objective is to maximize the cache hit ratio—the frequency with which requested data is found in the cache—while operating within strict memory constraints. Common strategies include Least Recently Used (LRU), which discards the stalest entry, and Least Frequently Used (LFU), which evicts items with the lowest access count.
Glossary
Cache Eviction Policy

What is a Cache Eviction Policy?
A cache eviction policy is the algorithmic logic that determines which data to discard when a cache reaches its maximum capacity, directly balancing memory utilization against hit rate.
In AI inference engines, the eviction policy directly governs the Time to First Token (TTFT) and overall throughput. A poorly chosen policy triggers a thundering herd problem, where mass evictions cause cascading cache misses and latency spikes. Modern Key-Value (KV) cache systems for large language models often implement hybrid policies that blend recency and frequency heuristics to preserve high-value context tensors.
Core Characteristics of Eviction Policies
The algorithm that determines which data to remove from a full cache, directly impacting AI inference speed and cost.
Least Recently Used (LRU)
The most common eviction policy that discards the item with the oldest access timestamp first.
- Mechanism: Maintains a doubly-linked list; accessed items move to the head, eviction always targets the tail.
- Assumption: Data accessed recently will likely be accessed again soon (temporal locality).
- AI Context: Effective for repeated prompt prefixes in LLM serving, where system prompts and few-shot examples are reused across requests.
- Weakness: Suffers from cache pollution during large sequential scans, where one-time data flushes out frequently used entries.
Least Frequently Used (LFU)
Evicts the entry with the lowest access count, prioritizing items with sustained popularity over recent one-hit wonders.
- Mechanism: Each cache line maintains a frequency counter incremented on access; the minimum counter is evicted on overflow.
- AI Context: Ideal for embedding caches in RAG architectures where popular document chunks are queried repeatedly.
- Weakness: Cache pollution from formerly popular items that are no longer relevant; requires aging mechanisms like LFU with Dynamic Aging to decay old counters.
Time-To-Live (TTL) Based Eviction
A deadline-driven policy where entries are automatically invalidated after a predefined expiration duration, regardless of access patterns.
- Mechanism: Each entry carries an absolute expiration timestamp; a background scavenger thread or lazy check on access removes stale items.
- AI Context: Critical for semantic cache implementations where factual data (e.g., stock prices, weather) has a known shelf-life and serving stale results is unacceptable.
- Implementation: Often combined with LRU as a hybrid policy—TTL handles temporal invalidation while LRU manages capacity pressure.
First-In, First-Out (FIFO)
A simple queue-based policy that evicts entries strictly in the order they were inserted, ignoring all access patterns.
- Mechanism: Maintains a circular buffer or queue; the oldest inserted entry is always the eviction target.
- AI Context: Used in streaming inference pipelines where data is processed exactly once and temporal ordering matters, such as video frame analysis.
- Advantage: Extremely low computational overhead with no per-access metadata updates, making it suitable for high-throughput, low-latency GPU serving where cache management must not compete with inference.
Segmented LRU (SLRU)
A partitioned cache that splits entries into a probationary segment and a protected segment to prevent cache pollution from sequential scans.
- Mechanism: New entries land in probation; only on a second access are they promoted to the protected segment. Eviction always targets the probationary LRU.
- AI Context: Highly effective for KV-cache management in continuous batching inference servers, where new sequence prefixes must prove reuse value before displacing active generation contexts.
- Variant: Forms the basis of W-TinyLFU, used in high-performance Java caches like Caffeine.
Cost-Aware Eviction
A policy that assigns a retention score based on the computational expense of regenerating an item, not just its access recency or frequency.
- Mechanism: Each entry carries a recomputation cost (e.g., GPU milliseconds, token count); the eviction algorithm maximizes saved compute under capacity constraints.
- AI Context: Essential for speculative decoding caches and prompt compression caches, where regenerating a long, complex chain-of-thought trace is far more expensive than a simple embedding lookup.
- Formula: Eviction score = access_frequency × recomputation_cost / cache_size_consumed.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the algorithms that govern cache eviction, directly impacting AI inference latency, throughput, and infrastructure cost.
A cache eviction policy is a deterministic algorithm that selects which data item to remove from a full cache to make space for a new entry. The policy operates by evaluating a specific property of each cached item—such as its recency of access, frequency of use, or a predicted future value—and evicting the item deemed least valuable according to that metric. In AI inference systems, this mechanism is critical for managing the Key-Value (KV) cache in transformer architectures, where the policy directly determines whether a previously computed attention state must be recomputed, incurring significant latency and compute cost. The policy executes in constant or logarithmic time to avoid becoming a bottleneck itself.
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
Cache eviction policies are one component of a broader performance optimization landscape. These related concepts govern how data flows through AI inference pipelines.
Time to First Byte (TTFB)
A critical latency metric measuring the duration from an initial inference request to the first byte of the response arriving at the client. Cache hit ratios directly determine TTFB; a poorly tuned eviction policy forces recomputation, inflating this value. In real-time AI serving, TTFB targets are often < 100ms for interactive applications. Monitoring TTFB degradation is the primary signal that a cache eviction policy requires recalibration.
Thundering Herd Problem
A performance anti-pattern where a popular cached item expires, triggering a flood of concurrent requests that all simultaneously attempt to recompute the same value. This overwhelms backend resources. TTL-based eviction with jitter or probabilistic early expiration mitigates this. Without a defense, a single cache miss can cascade into an infrastructure outage.
Cache Poisoning
An attack where malicious data is injected into a web cache, causing it to serve harmful responses to legitimate users. In AI contexts, this can corrupt KV-cache entries or prompt-response pairs. Defenses include input validation, strict cache key normalization, and never caching responses to unauthenticated requests. A poisoned cache undermines model output integrity at scale.
Prefetch
A hardware and software optimization that proactively loads data into cache before it is explicitly requested. In AI inference, speculative prefetching of KV-cache blocks for predicted future tokens can mask memory latency. However, aggressive prefetching can pollute the cache with unused data, forcing a well-tuned eviction policy to waste cycles discarding it.
Lock-Free Programming
A concurrency control paradigm that guarantees system-wide progress without mutual exclusion locks. Essential for high-throughput AI serving where multiple inference requests contend for shared cache structures. Lock-free LRU or LFU implementations prevent priority inversion and ensure that eviction decisions never block request processing, maintaining consistent tail latency.
Garbage Collection Pause
A stop-the-world event in managed runtimes (Java, Go, .NET) where all application threads halt while memory is reclaimed. For in-memory caches, a GC pause can freeze eviction logic and request serving simultaneously, causing latency spikes exceeding 100ms. Mitigations include off-heap caching, value types, and tuning GC to prioritize short pause times over throughput.

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