Version 1.2.1
Lightweight node.js and browser module for cache data in memory.
- lightweight script;
- easy to use;
- no requires except node.js or browser.
Via npm:
// may be later
Manually:
git clone [email protected]:alfabank/ncache.git
// var cache = require('./ncache');
const cache = require('./ncache');
cache.set('foo', 'bar', 100500);
console.log(cache.get('foo'));
This function designed for work with settings of cache. First two forms is a setters, and the last one is a getter. 'data' in second form means a key-value object with settings.
In this moment this settings exists:
cacheDefaultTime
(def: 5 * 60 * 1000) - default time for cache;cacheClearProb
(def: 0.01) - probability of calling clear routine.
Return md5 hash of given string. In [0-9a-h] format. Internal function but can be useful in external cases. Inplemented only under node.js. Throw an error in browser.
Return hash of given string. In Int32 format. Internal function but can be useful in external cases.
Return flag with state of cached value found by 'key'. Meant the true only if value by key exists an not become rotten.
Return value by key. If absent or rotten returns null
.
Remove value from storage by given key. If end with '*' will remove all key-values starts with key.
Function for cache values. Getting one value per time in first form, or array of values in second form. 'data' must by an array of objects with keys matching first form.