#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
🗃️ FREE · STEP BY STEP

LRU Cache Visualizer: Least Recently Used, Made Visible

Set a capacity, list operations, and replay how items move to the front and the oldest is evicted.

  • ✅ Hits and misses
  • 🗑️ Evictions
  • ⚡ O(1) design

How to use the LRU Cache Visualizer

  1. 1. Set it upChoose a capacity (1–8) and type operations: put key value or get key.
  2. 2. RunPress Run.
  3. 3. ReplayStep through: the most recent item is on the left, the next to be evicted on the right.

Worked example

With capacity 3, the sample puts 1, 2 and 3, so the order is 3, 2, 1. get 1 is a hit and moves 1 to the front: 1, 3, 2. put 4 finds the cache full and evicts 2, the least recently used. get 2 is then a miss. get 3 is a hit, put 1 Z updates key 1 and moves it to the front, and get 4 is a hit. The result: 3 hits, 1 miss and 1 eviction, with the final order 4, 1, 3.

How a real LRU cache is O(1)

A hash map finds a key's node instantly, and a doubly linked list keeps nodes in order of use. On get, the node is unlinked and moved to the front; on put, a new node goes to the front and, if the cache is full, the tail node is removed and its key deleted from the map. Every step is constant time. In Java, LinkedHashMap with access order and removeEldestEntry does this; in Python, OrderedDict with move_to_end, or functools.lru_cache for functions.

Where LRU is used

  • Browser and CDN caches, database buffer pools and operating-system page caches.
  • Memoising expensive function calls.
  • A very common design question: LeetCode's LRU Cache problem asks for exactly this structure.

Frequently asked questions

Does put on an existing key count as use?

Yes. It updates the value and moves the key to the front, as most implementations do.

What's the difference from LFU?

LFU evicts the least frequently used item; LRU evicts the one unused for the longest time.

Can keys be text?

Yes. Keys and values can be any text without spaces in the key.

Is the LRU cache visualizer free?

Yes. You can use the LRU cache visualizer without signing up. The first time you run it, we ask once for your name and WhatsApp number; after that the LRU cache visualizer and every other Uncodemy tool open straight away.

More free tools

See all free tools