Skip to content

Cache results of target function (if function return results in promise).

License

Notifications You must be signed in to change notification settings

ria-com/node-cacher-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-cacher-promise

Cache results of target function (if function return results in promise)

This module change name to node-cacher-promise and move to repository to https://github.com/ria-com/node-co-cache-wrapper

example

Add cache cache opportunity for simple generator - testGenerator:

var Q = require("q"),
    cacher = require("cache-promise");

var testMethodPromise = function testMethodPromise (a) {
    return Q.delay(a+1, 1000);
};

cacher(testMethodPromise,[4],{ cacheTime: 3 }).done(function (data) {
    console.log('first launch: ' + data); // wait 1 sec and get '5'
    cacher(testMethodPromise,[4],3).done(function (data) { // { cacheTime: 3 } equivalent '3'
        console.log('second launch: ' + data); //  get '5' from cache immediately
    },onerror);
},onerror);

function onerror(err) {
    console.error(err.stack);
}

simple test

Start testing module:

$ cd node-cache-wrapper
$ npm install
$ npm test

config

co-cacher use config module. Example of config (./config/default.js):

module.exports = {
    // https://github.com/3rd-Eden/node-memcached
    memcached: {
        servers: 'localhost:11211', // You can either use: String, Array, Object
        options: {
            poolSize: 20
        }
    },
    cache: {
        expires: 120, // Default cache expires in seconds
        storage: 'memcached',
        key: {
            prefix: 'cw_',
            crc32: false
        }
    }
};

roadmap

  • Add redis storage support

About

Cache results of target function (if function return results in promise).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published