Simple explanation of an LRU cache
An LRU (least recently used) cache is a cache that saves memory by only storing the n most used items.
It has two operations: get, and put that both run in constant time.
This is implemented using a combination of a hash table and a doubly linked list, in which the keys in the hash table point to individual nodes on the linked list.
The head of the linked list is considered the least recently used while the tail is considered the most recently used.
The get operation takes a key, and if it exists in the hash table, returns the node on the linked list. It then removes that node from the linked list and then re-attaches it to the tail.
The put operation will attach a new node to the tail of the linked list, and create a new key value pair in the hash table. If there are now more than n items in the cache, then you will now remove the head of the linked list and remove its key value pair from the hash table.





















