node-modules/ylru

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

Homepage:

Size: 18

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ylru

NPM version build status Test coverage David deps Known Vulnerabilities npm download

hashlru inspired

hashlru is the Simpler, faster LRU cache algorithm. Please checkout algorithm and complexity on hashlru.

ylru extends some features base on hashlru:

Usage
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 });
API
LRU(max) => lru

initialize a lru object.

lru.get(key[, options]) => value | null

Returns the value in the cache.

lru.set(key, value[, options])

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.

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',

License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.