Name: ylru
Owner: node_modules
Description: Add "expire", "allow set empty value" extends on hashlru
Forked from: dominictarr/hashlru
Created: 2016-12-29 03:42:03.0
Updated: 2018-04-27 01:39:10.0
Pushed: 2017-07-18 04:32:44.0
Size: 18
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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
t LRU = require('ylru');
t lru = new LRU(100);
set(key, value);
get(key);
alue2 will be expired after 5000ms
set(key2, value2, { maxAge: 5000 });
et key and update expired
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
.
t lru = new LRU(3);
set('key 1', 'value 1');
set('key 2', 'value 2');
set('key 3', 'value 3');
set('key 4', 'value 4');
keys(); // [ 'key 4', 'key 1', 'key 2', 'key 3']
ache: {
'key 4': 'value 4',
cache: {
'key 1': 'value 1',
'key 2': 'value 2',
'key 3': 'value 3',