Inferensys

Glossary

Least Recently Used (LRU)

A cache eviction policy that discards the item with the oldest access timestamp first, operating on the assumption that recently accessed data is most likely to be reused.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
CACHE EVICTION POLICY

What is Least Recently Used (LRU)?

Least Recently Used (LRU) is a cache eviction algorithm that discards the item with the oldest access timestamp first, operating on the assumption that data accessed recently is most likely to be reused soon.

Least Recently Used (LRU) is a deterministic cache eviction policy that maintains a strict ordering of items based on their last access time. When the cache reaches its memory capacity and a new entry must be inserted, the algorithm identifies and removes the entry that has remained unaccessed for the longest duration. This temporal locality principle is implemented using a doubly linked list and hash map, achieving O(1) time complexity for both lookups and evictions, making it highly efficient for sovereign inference caching layers where predictable latency is critical.

In sovereign AI infrastructure, LRU is deployed within semantic caches and KV-Caches to manage limited GPU memory and local storage. While effective for workloads with strong recency bias, LRU can suffer from cache thrashing under sequential scan patterns that evict data just before it is reused. For environments requiring strict data residency, LRU ensures that eviction logic remains deterministic and auditable, preventing stale foreign data from persisting in geofenced cache deployments while maintaining high hit rates for frequently repeated inference requests.

CACHE EVICTION MECHANICS

Key Characteristics of LRU

The Least Recently Used (LRU) algorithm is a foundational cache eviction policy that operates on the principle of temporal locality—the assumption that data accessed recently will likely be accessed again soon. It systematically discards the item with the oldest access timestamp when the cache reaches capacity.

01

Temporal Locality Assumption

LRU is built entirely on the temporal locality heuristic: if a piece of data was accessed recently, it has a high probability of being accessed again in the near future. This makes it highly effective for workloads with recency bias, such as user session data or sequential API calls. Unlike random eviction, LRU actively preserves the working set of hot data, maximizing the cache hit ratio for predictable access patterns. However, it performs poorly when confronted with sequential scans that load large, one-time-use datasets, as these scans flush the entire working set of frequently accessed items.

O(1)
Access Complexity
02

Doubly Linked List + Hash Map Implementation

The canonical high-performance LRU implementation combines two data structures to achieve constant-time operations:

  • Hash Map: Provides O(1) lookups by key to locate any cached entry instantly.
  • Doubly Linked List: Maintains access order, with the most recently used item at the head and the least recently used at the tail. On every cache hit, the accessed node is detached and moved to the head of the list. On eviction, the tail node is removed. This dual-structure approach ensures that both reads and writes remain fast even as the cache grows, making it suitable for high-throughput inference caching layers.
O(1)
Eviction Complexity
03

Vulnerability to Cache Pollution

LRU is susceptible to cache pollution, a scenario where low-value, one-time-access data displaces frequently used entries. This occurs during large sequential scans or bulk data loads where each new item is accessed once and never again. Because LRU tracks only recency, not frequency, these ephemeral items occupy the head of the list and push genuinely hot data toward eviction at the tail. In sovereign inference caching, this can manifest when a batch of unique, low-similarity queries floods the semantic cache, evicting high-value shared responses. Mitigations include LRU-K variants that track the timestamp of the K-th most recent access.

04

LRU vs. LFU: Recency vs. Frequency

LRU and Least Frequently Used (LFU) represent two distinct eviction philosophies:

  • LRU: Evicts based on recency of access. Ideal for workloads where recent items are most valuable, such as news feeds or session tokens.
  • LFU: Evicts based on access count. Ideal for stable, long-lived reference data accessed repeatedly over time. LRU adapts quickly to shifting access patterns, while LFU suffers from cache pollution by history—old items with high historical counts resist eviction even after becoming irrelevant. Hybrid policies like ARC (Adaptive Replacement Cache) dynamically balance recency and frequency to capture the strengths of both.
05

LRU in Sovereign Inference Caching

In sovereign AI deployments, LRU serves as the default eviction policy for managing KV-Cache memory and semantic cache entries. When GPU memory is constrained, LRU evicts the KV-Cache tensors for the least recently processed prompt, freeing accelerator memory for new inference requests. For semantic caches storing embedded query-response pairs, LRU ensures that frequently asked questions remain instantly retrievable while stale, one-off queries are purged. The deterministic nature of LRU also simplifies cache telemetry and debugging in air-gapped environments where observability tooling may be limited.

06

LRU-K and Approximate Variants

Standard LRU can be refined into LRU-K, which tracks the timestamp of the K-th most recent access rather than the single most recent. This filters out one-hit-wonder items that pollute the cache. Common variants include:

  • LRU-2: Evicts items based on their second-to-last access time, requiring at least two accesses to establish value.
  • 2Q (Two Queue): Maintains separate FIFO and LRU queues, admitting items to the main LRU queue only after a second access.
  • Clock (Second Chance): An approximate LRU using a circular buffer and reference bits, trading perfect accuracy for lower memory overhead. These variants are critical for sovereign caching layers where memory is a finite, expensive resource and every eviction decision impacts inference latency.
CACHE EVICTION STRATEGY COMPARISON

LRU vs. Other Eviction Policies

Comparative analysis of Least Recently Used (LRU) against alternative cache eviction algorithms based on operational complexity, hit ratio characteristics, and suitability for sovereign inference workloads.

FeatureLRULFUFIFOTTL-Based

Eviction Trigger

Discards item with oldest access timestamp

Discards item with lowest access frequency count

Discards item inserted earliest (queue order)

Discards item exceeding pre-defined lifespan

Primary Assumption

Temporal locality: recently accessed data will be reused soon

Frequency locality: popular items remain popular

Insertion order predicts obsolescence

Data freshness decays predictably over time

Metadata Overhead

O(1) with doubly-linked list and hash map

O(log n) with heap or sorted structure

O(1) with simple queue

O(1) with per-entry timestamp

Resistant to Scan Pollution

Handles Bursty Access Patterns

Memory Efficiency

Moderate: two pointers per entry

Higher: frequency counter per entry

Low: single pointer per entry

Low: timestamp per entry

Best Suited Workload

Session-based queries, conversational AI context

Static reference data, embedding lookups

Streaming data, log processing

Time-sensitive data with known staleness windows

Cold Start Behavior

Populates naturally via access order

Requires warm-up to build frequency counts

Populates in insertion order

Requires pre-configured TTL values

LRU CACHE EVICTION

Frequently Asked Questions

Clear, technical answers to the most common questions about the Least Recently Used eviction policy and its role in sovereign inference caching.

Least Recently Used (LRU) is a cache eviction policy that discards the item with the oldest access timestamp first, operating on the assumption that recently accessed data is most likely to be reused. The mechanism maintains a doubly linked list and a hash map. On a cache hit, the accessed item is moved to the head of the list. On a cache miss that requires eviction, the item at the tail is removed. This guarantees O(1) time complexity for both lookups and insertions, making it deterministic and predictable for latency-sensitive inference workloads.

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.