Caching is a method of storing data with the assumption that they will useful to process future requests faster.
There's always a limit to the amount of data that can be stored in the cache. When we hit the cache limit while we're trying to add a new item into the cache, we need to find a way to replace an existing item. Algorithms that perform this task are called cache replacement algorithms. In this video, I'm talking about a cache-replacement-algorithm called LRU/Least Recently Used cache. This is also a common interview problem in big tech companies like Google, Amazon, Facebook, Apple.
Here, I'll be showing you how to solve the Leetcode problem - LRU Cache
Problem statement can be found here: https://leetcode.com/problems/lru-cache/
You need to know the data structures HashMap and Doubly linked lists. We use HashMaps for fast look ups from within cache.
We use doubly linked list to keep the order in the cache items were used. First of the list is always the most recently used item. Tail is the least recently used item. If we use one of the elements, we need to remove it from the list and add it to the front of the list. Removing and adding to front of a list can be efficiently done using doubly linked list, which is why we chose a doubly linked list. Whenever we have to add a new item to the cache but the cache capacity is already reached, we can remove the last element in the doubly linked list because that is the least recently used item.
References
https://en.wikipedia.org/wiki/Cache_(...)
https://leetcode.com/problems/lru-cache/
Music credits: http://bensound.com/
On this page of the site you can watch the video online Implementing LRU Cache - Common Interview problem - Leetcode with a duration of hours minute second in good quality, which was uploaded by the user Friendly Neighborhood Coder 18 October 2020, share the link with friends and acquaintances, this video has already been watched 197 times on youtube and it was liked by 23 viewers. Enjoy your viewing!