Implements an LRU cache.
var lruly = require('lruly');
var cache = lruly();
cache.add('foo', 'hello world');
$ npm install -g lruly
$ component install cfddream/lruly
Create the LRU cache and set maxEntries
,
if maxEntries
is zero, the cache has no limit:
var cache = lruly(8964);
Add a entiry:
cache.add('module', { version: '0.0.1', name: 'lruly' });
Get the entry's value:
cache.get('module'); // { version: '0.0.1', name: 'lruly' }
Remove the entry by key:
cache.on('evicted', function (key, value) { /* do something */ });
cache.remove('module');
Get the number of entries in the cache:
cache.len();
Clean the cache:
cache.clean();
To run the test suite first invoke the following command within the repo, installing the development dependencies:
$ npm install
then run the tests:
$ make test