lite-lru
A simple LRU cache module that is optimized for frequent serialization, only supports number keys and uses binary search to locate the entries
Installation
$ npm install --save lite-lru
Usage
const LiteLRU = ; const size = 5;const lru = size;const key = lru; // Later you can get back the value:lru; // > 'any value'lru;lru; lru; // > undefined
Note that get
, set
and delete
methods use binary search
There's a toJSON
method defined which basically returns the internal
array. You can pass that array to LiteLRU constructor:
new LiteLRU(50, JSON.parse(JSON.stringify(new LiteLRU(50))))
You can set callback for when a value is added, so that you can save the cache somewhere:
lru.onAdd = () => {
localStorage.cache = JSON.stringify(lru);
}
License
MIT © Olindata BV