What is an LRU Cache Visualizer?
An LRU cache visualizer shows how a least recently used cache keeps fast key lookup while tracking which item was used most recently. When the cache reaches capacity, it evicts the least recently used item.
LRU caches are usually explained with a hash map and a doubly linked list. The hash map gives direct key lookup. The linked list keeps recency order from most recently used to least recently used.
For the full cluster of related tools, browse the Data Structure Visualizers hub.
How to use this LRU cache visualizer
- Set the cache capacity.
- Run
put(key, value)to add or update an item. - Run
get(key)to mark an item as recently used. - Paste a batch of operations such as
put A 1,get A, andput B 2. - Watch the hash map, recency list, hits, misses, and eviction output update.
The visual order is most recently used on the left and least recently used on the right.
LRU cache with hash map and linked list
A hash map alone can find keys quickly, but it does not preserve recency order by itself. A linked list can preserve order, but search is slow without a map.
An LRU cache combines both ideas. Compare this page with the Hash Table Visualizer and the Linked List Visualizer to see the two parts separately.