A fast in memory cache with TTL and LRU support
JavaScript
Switch branches/tags
Nothing to show
Permalink
Failed to load latest commit information.
benchmark
lib
test
.gitignore
.jshintignore
.jshintrc
.travis.yml
README.md
package.json Repo clean up, with extra quality checks and passing tests Jan 8, 2014

README.md

ttl-lru-cache - A fast in memory cache with TTL and LRU support

build status

Installation

  npm install ttl-lru-cache

Usage

var cache = require('ttl-lru-cache')({ maxLength: 100 });

cache.set('a', 'Hello');

var a = cache.get('a');

// a = 'Hello'

// TTL Example
cache.set('b', 'Hello', 1000); // Add TTL in ms
var b = cache.get('b');
// b = 'Hello'

setTimeout(function() {
  var b = cache.get('b');
// b = undefined
}, 2000);

// Events
cache.set('c', 'Hello', 1000); // Add TTL in ms
cache.on('expired', function(key, value){ console.log('Expired', key, 'who had the value:', value); });

setTimeout(function() {
  var c = cache.get('c');
  // => Expired c who had the value: Hello
}, 2000);

Benchmark against lru-cache

  npm install
  make bench

Credits

Paul Serby follow me on twitter @serby

Licence

Licenced under the New BSD License