LRU cache with locking

npm install cache-money-flow
1 downloads in the last month

Cache Flow Money

cache-flow-money is a simple LRU cache for node.

It supports both synchronous and asynchrous population for the cache, and it supports locking items so they cannot be evicted.


npm install cache-flow-money


var LRUCache = require('cache-flow-money');

var maxItems = 10;
var options = {
  populate: function(key) { return key + key; },
  async: false
var cache = new LRUCache(maxItems, options);

cache.get('foo') === 'foo-foo' // populated automagically

You can also use async populate methods.

var options = {
  populate: function(key, cb) {
    cb(key + "-" + key);
  async: true

var cache = new LRUCache(maxItems, options);

cache.get('foo', function(v) {
  v === 'foo-foo'; // populated


Evicting items (which happens on inserts when cache is full), is O(n), with n being the number of items in the cache.

Everything else (retrieving, locking, unlocking, setting), is O(1).


You can lock items that are in use to prevent them from being evicted.

var cache = new LRUCache(5);

cache.set('foo', 'bar');
cache.set('baz', 'bam');
for (var i = 0; i < 10; ++i) {
  cache.set('foo' + i, i);

cache.get('foo'); // 'bar'
cache.get('baz'); // undefined


Cache-flow-money is under an MIT Style (jslint) license.

See the LICENSE file for details.

npm loves you