Skip to content

Instantly share code, notes, and snippets.

@udayvunnam
Last active June 6, 2021 06:11
Show Gist options
  • Save udayvunnam/68a5b6b237dbe2921ecd178467a651ea to your computer and use it in GitHub Desktop.
Save udayvunnam/68a5b6b237dbe2921ecd178467a651ea to your computer and use it in GitHub Desktop.
LRU cache usage in Javascript
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