Last active
June 6, 2021 06:11
-
-
Save udayvunnam/68a5b6b237dbe2921ecd178467a651ea to your computer and use it in GitHub Desktop.
LRU cache usage in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lruCache = new LRU(3); | |
lruCache.write('a', 123); | |
lruCache.write('b', 456); | |
lruCache.write('c', 789); // lru is 'a' | |
lruCache.read('a'); // lru is 'b' | |
// Now max limit 3 is reached. Let's add a new element | |
lruCache.write('d', 0); // lru 'b' is removed | |
console.log(lruCache); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment