1.0.5 • Published 7 years ago

biglrucache v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

biglrucache

NPM Version NPM Downloads

LRU Cache for Javascript

Installation

Node.js:

$ npm install biglrucache

Bower:

$ bower install biglrucache

Browser:

<script src="/pathTo/biglrucache.js"></script>

Usage

Require by Node.js

var biglrucache = require('biglrucache');

Basic usage

var cache = biglrucache(10, function(key, value) {});
cache.set('a', 1);
cache.set('b', 2);
cache.has('a'); // true
cache.get('a'); // 1
cache.keys(); // ['a', 'b']
cache.keys(function(k, v) {return v < 2}); // ['a']
cache.keys(function(k, v) {return v > 1}); // []
cache.values(); // [1, 2]
cache.del('a');
cache.keys(); // ['b']

Parameters

NameTypeDescriptionRequirement
capacityintthe capacity of cache keys, min: 3, default: 100000N
notifyfunctionprocessor a key be removed when cache shrinkedN

API

biglrucache#get(key)

Get a cache by key.

biglrucache#set(key, value)

Set new or update cache by key, call notify when shrink keys.

biglrucache#del(key)

Delete a cache by key, not call the notify.

biglrucache#has(key)

Test a cache by key

biglrucache#hit(key)

Refresh a cache by key

biglrucache#clear(key)

Clear all cache, not call the notify.

biglrucache#info()

Get information

Result

NameTypeDescriptionRequirement
capacityintthe capacity of cache keysY
lengthintThe count of cache keysY

biglrucache#keys(predicate)

Return cached keys array when predicate return true (break on return false).
The entry order from old to new.

biglrucache#values(predicate)

Return cached values array when predicate return true (break on return false).
The entry order from old to new.

License

MIT

1.0.5

7 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago