i-cache
v0.0.2
Published
A simple cache util
Downloads
3
Readme
i-cache
The simplest in-memory cache which store and get objects as pure json structure.
Maybe your replacement when u don't have memcached.
Installation
$ npm install i-cache
Usage
var iCache = require('i-cache');
API
Public methods
iCache.set cache with the given key.
key
: String The keyvalue
Object The value, will be stored with JSON.stringifylifetime
: Number (Optional) After how long should the key expire measured inseconds
callback
: Function (Optional)
iCache.set('hi', 'Hello World');
iCache.get get by key.
key
: String The keycallback
: Function (Optional)
var value = iCache.get('hi');//Hello World
equals to
iCache.get('hi', function(e, value){
console.log(value);//Hello World
});
iCache.del delete by key.
iCache.del('hi');
var value = iCache.get('hi');//undefined
iCache.reset empty all the caches.
iCache.reset();
iCache.keys return all the keys of cache objects.
iCache.reset();
iCache.set('hi', 1);
iCache.set('hello', 1);
iCache.keys;//["hi", "hello"]
iCache.stats .
var stats = iCache.stats();
/** what stats looks like:
{
hits: 0,//the number of cache hits
misses: 0,//the number of cache misses
keys: 0//the total number of cached keys
}
**/