Least Recently Used (LRU)

About

Least Recently Used is a caching mechanism. It evicts the least recently used item.

Drawing

In LRU, you mix a Doubled Linked List with a HashMap.

  • The Doubled Linked List is used to maintain the order for the accessed items. This is crucial to keep the trimCache() O(1)O(1).

  • The HashMap is used to access Linked List items in O(1)O(1).

With this mix, you can access and update any cached values in constant time.

Implementation

Last updated