LRU Cache
LRU Cache
Rear Front
Internal Hashmap
Key Value
k1 Node
k2 Node
Storing the nodes of linked list
in the hashmap by their key k3 Node
k4 Node
Add a key-value pair to the Cache
Key Value
Internal Hashmap
k2 k1 Node
Value2
k2 Node
k3 Value3
k3 Node
k4 Node
Key Value
Internal Doubly Linkedlist
Node Node Node Node
k1 Value1 Key = k1 Key = k3 Key = k4 Key = k2
Node next Node next Node next Node next
Node prev Node prev Node prev Node prev
k2 Value2
k3 Value3
Rear Front
Node
Get (K4) Node Node Node
Value4
k1 Node k1 Node
k2 Node k2 Node
k3 Node k3 Node