Hash Cache
A simple bit of code for creating an in-memory object store/cache. LRU Cache has a lot more bells & whistles if you're looking for something production ready.
Install
npm install hashcache
-or-
npm install ben-bradley/hashcache
Use
var HashCache = ; var cache = // expires: 0 // never expire expires: 1000 * 10 // 1000ms * 10 = 10sec expiration for items; cache; ;)
Methods
get('key')
Returns the cached value associated with 'key'
and reset the expiration timer.
peek('key')
Returns the cached value associated with 'key'
and does NOT reset the expiration timer.
set('key', value, [update])
Sets a new cached value
key
= a string value to reference the elementvalue
= the variable data that you want to cacheupdate
= (optional) a callback to update the value of the element
var cache = new HashCache({
expires: 100
});
cache.set('key1', 'value1', function(update) {
// do something to get a newValue
update(newValue);
});
Test
npm test
-or-
mocha -R spec