LRU Cache - Explanation, Java Implementation and Demo

preview_player
Показать описание
Explanation and implementation of the LRU (Least Recently Used) Cache in Java. We do a hands on coding using Java and also try to run our cache.
This is also one of the very common interview questions asked in software engineering.

Рекомендации по теме
Комментарии
Автор

In the 'put' function, inside 'if(currentNode != null)' there should be a 'return' in the end of this block. This is because we don't need to create new node if the node with that key is already present.
(or, put the remainig lines in that function in 'else' block).

The code gist on GitHub is updated

BhriguSrivastava
Автор

Very good explanation. Please load more videos.

akhilsrivastava
Автор

hi! the UseCache code is available somewhere? thanks for the tips!

gamopim
Автор

Thanks for the explaination! i think in put function, in block where currentNode !=null there should be return also.

gouravkumar
Автор

when it refers 4 again order must change, so as for 2 if you don't change order, how will you decide which need to delete for new entry?

dewendrapandey
Автор

Just one question in my mind.. If we are adding a new element and capacity is available, then why we are adding it at the beginning??

ankitgupta-phnk
Автор

Hey brother, there is a fundamental problem you have missed in the LRU .
lets say we have 2->4 ->7 and again there is 4 which is requested we need to adjust the linked list again to 4->2->7 coz 4 is now recently used and the order should be retained
lets say again 7 is hit, now the order will become 7->4>2 if you carefully observer now the least recently used is actually 2 - please fix this

rozersmith