Inferensys

Glossary

Cache Eviction Policy

A cache eviction policy is the algorithmic rule that determines which data to discard when a cache reaches its capacity, balancing hit rate and memory usage to optimize AI inference speed and cost.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
INFERENCE OPTIMIZATION

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.

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.

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.

CACHE MANAGEMENT FUNDAMENTALS

Core Characteristics of Eviction Policies

The algorithm that determines which data to remove from a full cache, directly impacting AI inference speed and cost.

01

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.
O(1)
Time Complexity
02

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.
O(log N)
Min-Heap Complexity
03

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.
Deterministic
Freshness Guarantee
04

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.
O(1)
Insert/Evict Overhead
05

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.
2 Segments
Minimum Partitioning
06

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.
Greedy Knapsack
Optimization Problem
CACHE EVICTION POLICY

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.

Prasad Kumkar

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.