hashlru is the Simpler, faster LRU cache algorithm.
Please checkout algorithm and complexity on hashlru.
ylru extends some features base on hashlru:
cache value can be expired.
cache value can be empty value, e.g.: null, undefined, '', 0
Usage
import { LRU } from 'ylru';const lru = new LRU(100);lru.set(key, value);lru.get(key);// value2 will be expired after 5000mslru.set(key2, value2, { maxAge: 5000 });// get key and update expiredlru.get(key2, { maxAge: 5000 });
API
new LRU(max) => lru
initialize a lru object.
lru.get(key[, options]) => value | null
{Number} options.maxAge: update expire time when get, value will become undefined after maxAge pass.
Returns the value in the cache.
lru.set(key, value[, options])
{Number} options.maxAge: value will become undefined after maxAge pass.
If maxAge not set, value will be never expired.
Set the value for key.
lru.keys()
Get all unexpired cache keys from lru, due to the strategy of ylru, the keys' length may greater than max.