Inferensys

Glossary

Cache Eviction Policy

An algorithm that determines which data to remove from a full cache to make space for new content, with LRU-K being a variant that considers the time of the last K references.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
CACHE MANAGEMENT

What is Cache Eviction Policy?

A cache eviction policy is an algorithm that determines which data to remove from a full cache to make space for new content, optimizing for future hit ratios.

A cache eviction policy is the deterministic algorithm that governs which data item is removed when a cache reaches its storage capacity and a new item must be inserted. The policy's objective is to maximize the cache hit ratio by retaining items with the highest probability of future access. Common strategies include Least Recently Used (LRU), which discards the item with the oldest access timestamp, and Least Frequently Used (LFU), which tracks access counts to identify cold data.

Advanced variants like LRU-K improve precision by considering the timestamp of the K-th most recent reference, distinguishing between frequently and sporadically accessed objects. In proactive caching for AI-enhanced RANs, eviction policies must also account for content freshness and predicted mobility patterns, balancing temporal locality with the cost of backhaul retrieval to ensure seamless edge delivery.

CACHE MANAGEMENT FUNDAMENTALS

Core Characteristics of Eviction Policies

The algorithmic logic that governs which data is discarded when a cache reaches its capacity limit, directly impacting hit ratios and system performance.

01

The Recency vs. Frequency Trade-off

Eviction policies must balance two competing signals:

  • Recency: How recently was the data accessed? (e.g., LRU)
  • Frequency: How often is the data accessed? (e.g., LFU)

Pure LRU is vulnerable to cache pollution from sequential scans that evict frequently-used hot items. LRU-K bridges this gap by tracking the timestamp of the last K references, effectively filtering out one-hit wonders while retaining genuinely popular content. This is critical in Content Delivery Networks where a viral video segment exhibits high frequency, while a one-time DNS lookup only shows recency.

02

TTL-Based Invalidation

A time-to-live (TTL) is an explicit expiration timestamp assigned to each cached object. Unlike capacity-driven eviction, TTL enforces content freshness by removing data that has exceeded its validity period, regardless of access patterns.

  • Absolute TTL: Object expires at a fixed wall-clock time (e.g., a stock price valid for 15 minutes).
  • Sliding TTL: Expiration resets on each access, keeping frequently-read data alive.

In MEC Caching for autonomous vehicles, stale sensor data must be evicted aggressively using short TTLs to prevent decisions based on outdated environmental models.

03

Cost-Aware Eviction

Advanced policies incorporate the latency penalty of a cache miss to prioritize eviction candidates. The algorithm calculates a value score, often defined as:

Score = (Fetch Cost × Frequency) / Size

  • Fetch Cost: The round-trip time to retrieve the object from the origin server.
  • Size: Larger objects consume more cache slots, so size-aware policies like GDStar optimize for byte-hit ratio rather than object-hit ratio.

This is essential in Joint Caching and Computing scenarios where evicting a pre-computed inference result could trigger an expensive GPU-bound recomputation.

04

Approximate LRU with Sampling

Exact LRU requires maintaining a global doubly-linked list, which introduces lock contention in high-throughput, multi-threaded caches like Redis. Production systems often use approximate eviction:

  • Redis Allkeys-LRU: Samples N random keys and evicts the least recently used among the sample.
  • Clock (Second Chance): A circular buffer with a reference bit. The algorithm scans for an unreferenced page, clearing bits as it goes.

These approximations achieve near-LRU performance with O(1) complexity per eviction, critical for Edge Pre-fetching nodes handling millions of requests per second.

05

Segmented and Multi-Tier Eviction

Modern caches partition storage into segments with distinct eviction policies to prevent destructive interference between workload types:

  • Segmented LRU (SLRU): Uses a probationary segment for new entries and a protected segment for items accessed at least twice. Eviction occurs only from the probationary segment.
  • TinyLFU: A frequency sketch (Count-Min Sketch) filters infrequent items before they enter the main cache, providing near-optimal hit ratios with minimal memory overhead.

This architecture underpins Caffeine, the high-performance Java caching library used in Apache Kafka and Apache Cassandra.

06

Machine Learning-Driven Eviction

Learned policies use neural networks to predict an object's future reuse distance, replacing hand-crafted heuristics:

  • Feature Engineering: Inputs include access frequency, recency, object size, content type, and temporal patterns (e.g., time of day).
  • LSTM-Based Predictors: Recurrent networks model sequential access patterns to forecast if an object will be requested again within a lookahead window.

In Proactive Caching for video streaming, an ML model can predict that a specific video tile will not be revisited, preemptively evicting it to make room for predicted popular content from a Content Popularity Prediction engine.

CACHE REPLACEMENT ALGORITHMS

Comparison of Common Eviction Policies

A technical comparison of algorithmic strategies for selecting which cache entry to discard when the cache is full and new data must be inserted.

FeatureLRULFULRU-K

Core Mechanism

Discards the least recently accessed item based on a single recency timestamp

Discards the item with the lowest total access frequency count

Discards the item whose K-th most recent access is oldest, using a backward K-distance metric

Primary Metric

Recency of last access

Cumulative access count

Inter-arrival time of last K references

Handles Bursty Traffic

Resistant to Scan Pollution

Memory Overhead

Low (doubly-linked list + hash map)

Low (frequency counter per entry)

Moderate (K history timestamps per entry)

Computational Complexity

O(1) per access

O(log N) with heap; O(1) with approximate LFU

O(log N) for priority queue maintenance

Correlated Reference Pattern Performance

Excellent for temporal locality

Poor; frequency bias ignores recency

Excellent; captures long-term correlation

Cold Start Sensitivity

Low; new items placed at MRU position

High; new items with low frequency evicted quickly

Low; uses last K references to establish pattern

CACHE EVICTION POLICY

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the algorithms that determine which data gets removed when a cache reaches its storage capacity.

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 metric for each cached object—such as recency of access, frequency of requests, or a cost function—and evicting the item with the lowest score. When the cache reaches its configured capacity threshold, the eviction algorithm executes atomically: it identifies the victim entry, invalidates it, writes the new data block into the freed space, and updates the cache metadata index. The choice of policy directly impacts the cache hit ratio, which is the percentage of requests served from cache without requiring a fetch from the origin server. In content delivery networks and edge computing environments, the eviction policy runs continuously on every SET operation, making its computational efficiency as critical as its predictive accuracy.

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.