LRU Cache is a dead simple implementation of, you guessed it, an LRU cache. If you're looking for a LRU cache with plenty of features, this is not the library you're looking for /end jedi mind trick.
The constructor function. maxSize
is the number of entries the cache will hold
before it starts evicting. maxSize
defaults to 100
.
Store an entry in the cache. key
is expected to be a string and entry
can be
anything, note however it'll be stored by reference.
Retrieves a stored entry from the cache. If the entry doesn't exist, undefined
will be returned.
var cache = new LruCache(3);
cache.set('one', 1);
cache.set('two', 2);
cache.set('three', 3);
cache.get('one');
cache.set('four', 4);
cache.get('one') === 1;
cache.get('two') === undefined;
cache.get('three') === 3;
cache.get('four') === 4;
Tests are written using Jasmine and ran with Karma.
To run LRU Cache's test suite with PhantomJS, run npm test
.
Found a bug? Create an issue on GitHub.
https://github.com/jharding/lru-cache/issues
For transparency and insight into the release cycle, releases will be numbered with the follow format:
<major>.<minor>.<patch>
And constructed with the following guidelines:
- Breaking backwards compatibility bumps the major
- New additions without breaking backwards compatibility bumps the minor
- Bug fixes and misc changes bump the patch
For more information on semantic versioning, please visit http://semver.org/.
Copyright (c) 2013 Jake Harding
Licensed under the MIT License.