![]() | Name | Last modified | Size | Description |
---|---|---|---|---|
![]() | Parent Directory | - | ||
![]() | History.md | 39 years ago | 443 | |
![]() | LICENSE | 39 years ago | 1.1K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
![]() | README.md | 39 years ago | 2.6K | f12eb36 documentaiton updates [كارل مبارك] |
![]() | index.js | 39 years ago | 2.3K | |
![]() | package.json | 2 years ago | 1.7K | 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك] |
hashlru inspired
hashlru is the Simpler, faster LRU cache algorithm. Please checkout algorithm and complexity on hashlru.
ylru extends some features base on hashlru:
null
, undefined
, ''
, 0
const LRU = require('ylru');
const lru = new LRU(100);
lru.set(key, value);
lru.get(key);
// value2 will be expired after 5000ms
lru.set(key2, value2, { maxAge: 5000 });
// get key and update expired
lru.get(key2, { maxAge: 5000 });
initialize a lru object.
{Number} options.maxAge
: update expire time when get, value will become undefined
after maxAge
pass.Returns the value in the cache.
{Number} options.maxAge
: value will become undefined
after maxAge
pass.
If maxAge
not set, value will be never expired.Set the value for key.
Get all unexpired cache keys from lru, due to the strategy of ylru, the keys
' length may greater than max
.
const lru = new LRU(3);
lru.set('key 1', 'value 1');
lru.set('key 2', 'value 2');
lru.set('key 3', 'value 3');
lru.set('key 4', 'value 4');
lru.keys(); // [ 'key 4', 'key 1', 'key 2', 'key 3']
// cache: {
// 'key 4': 'value 4',
// }
// _cache: {
// 'key 1': 'value 1',
// 'key 2': 'value 2',
// 'key 3': 'value 3',
// }