-
Notifications
You must be signed in to change notification settings - Fork 3
LRUCache
kavi castelo edited this page Nov 18, 2025
·
1 revision
LRU (Least Recently Used) is one of the simplest and most widely used eviction policies.
LRU evicts the item that was used least recently.
It approximates temporal locality — the assumption that recently accessed data is likely to be accessed again.
- Doubly linked list maintains recency order
- Hash map gives O(1) access
- On GET/PUT → move node to head
- Evict from the tail (LRU end)
flowchart LR
H((HEAD)) --> A[(K3)]
A --> B[(K7)]
B --> C[(K9)]
C --> T((TAIL))
const cache = new LRUCache(2);
cache.put(1, 100);
cache.put(2, 200);
cache.get(1);
cache.put(3, 300); // evicts key 2- Very simple
- O(1) operations
- Great under sequential workloads
- Fails under scan workloads
- Can't differentiate frequent vs. recent
All rights reserved © 2025 kavi castelo