0.0.2 • Published 11 years ago
i-cache v0.0.2
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-cacheUsage
var iCache = require('i-cache');API
Public methods
iCache.set cache with the given key.
key: String The keyvalueObject The value, will be stored with JSON.stringifylifetime: Number (Optional) After how long should the key expire measured insecondscallback: Function (Optional)
iCache.set('hi', 'Hello World');iCache.get get by key.
key: String The keycallback: Function (Optional)
var value = iCache.get('hi');//Hello Worldequals 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');//undefinediCache.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
}
**/