co-cache-wrapper
Wrap to cacher's all methods of target object. Now support co-cacher & cacher-promise
Last updated a year ago by apelsyn .
Original npm · Tarball
$ cnpm install co-cache-wrapper 
SYNC missed versions from official npm registry.

node-co-cache-wrapper

Wrap co-cacher in to target object with generators. Based on co-cacher & cacher-promise

This new location for repository https://github.com/ria-com/node-cache-wrapper .

example

Generators wrapper:

var wrapper = require('co-cache-wrapper'),
    co = require('co');

var myObject = {
    sum: function* (a,b) {
        return a+b;
    },
    hello: function* (name) {
        return "Hello, " + name;
    }
};

var myCachedObject = wrapper(myObject,180); // Cache all methods on 3 min
co(function *(){
    console.log(yield myCachedObject.hello("Oleg!"));
    console.log(yield myCachedObject.sum(7,2));
}).catch(function(e) {throw e; });

Warning: Wrapper work only for generator's for koajs or co library

Promises wrapper:

var wrapper = require('co-cache-wrapper'),
    Q = require('q');

var myObject = {
    sum: function (a,b) {
        var deferred = Q.defer();
        deferred.resolve(a+b);
        return deferred.promise;
    },
    hello: function (name) {
        return Q.delay("Hello, " + name, 1000);
    }
};

var myWrappedObject = wrapper(myObject,180,{cacherType: 'promise'}); // Cache all methods on 3 min
myWrappedObject.sum(7,2).done(function(value){
    console.log(value);
    myWrappedObject.hello("Oleg!").done(function(value){
        console.log(value);
    });
});
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (6)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |