node package manager

obj-cache

object cache for nodejs

cache

Object cache for nodejs.

Getting Started

npm install obj-cache

API

var cache_object=new cache(

{ name:'cache name', //optional keepalive:5601000, //optional,defalt 5 min loader:function(key,callback){}, dispose:function(value){} //optional });

cache_object.get(key,callback)

cache_object.try_get(key)

cache_object.exists(key)

cache_object.remove(key)

cache_object.clear()

cache_object.length

cache_object.dispose()

cache.cleanup()

cache.get_cache(name)

Sample

 
var cache=require('obj-cache');
var mycache=new cache(
    'mycache',
    1000*30,
    function(key,callback)
    {
        database.connect(
            key,
            function(err,conn)
            {
                callback(err,conn);
            }
            );
    },
    function(conn)
    {
        conn.close();
    }
);
 
...
 
mycache.get(
    'database connection string',
    function(err,conn)
    {
        conn.query(....);
 
    }
    );
 
....
 
//exiting application 
cache.cleanup(); //release resource in all caches