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.
Installation
npm install cache-flow-money
Usage
var LRUCache = ; var maxItems = 10;var options = { return key + key; } async: false;var cache = maxItems options; cache === 'foo-foo' // populated automagically
You can also use async populate methods.
var options = { ; } async: true; var cache = maxItems options; cache;
Performance
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)
.
Locking
You can lock items that are in use to prevent them from being evicted.
var cache = 5; cache;cache;cache;for var i = 0; i < 10; ++i cache; cache; // 'bar'cache; // undefined
License
Cache-flow-money is under an MIT Style (jslint) license.
See the LICENSE file for details.