manrajgrover / algorithms-js

Consumable Data Structures and Algorithms library in JavaScript
MIT License
198 stars 129 forks source link

Implemented LRU Cache Data Structure #54

Open strobelo opened 5 years ago

strobelo commented 5 years ago

Description of new feature, or changes

Introduces a class (LRUCache) which implements a least-recently-used cache data structure. LRU cache is most commonly known for its popularity in operating systems applications for managing system memory caches.

This implementation accepts entries as key-value pairs. If a new entry would exceed the cache's configured maximum size, the least recently retrieved items are removed and destroyed from memory until there is enough room for the new one.

By default, items are considered to have size 1. However, you can specify a custom size function for how big to consider items. For example, if you are storing strings in your cache with a maximum limit of 20, you could specify that the cache should consider the string's length as its size, you would effectively have a cache with a maximum size of 20 bytes.

Checklist

Related Issues and Discussions

Implements #17

People to notify

@manrajgrover