co-cacher
Caches the results of function|generator
Last updated 2 years ago by apelsyn .
Original npm · Tarball
$ cnpm install co-cacher 
SYNC missed versions from official npm registry.

node-co-cacher

A simple middleware for co library. Add cache opportunity for you function or generator

example

Add cache cache opportunity for simple generator - testGenerator:

var co = require('co'),
    wait = require('co-wait'),
    cacher = require('co-cacher');

var testGenerator = function* testGenerator (a) {
    yield wait(1000);
    return a+1;
};

co(function *(){
    var result = yield cacher(testGenerator, [4]);
    console.log(result); // wait 1 sec and get '5'
    result = yield cacher(testGenerator, [4]);
    console.log(result); // get '5' from cache immediately
}).catch(function(e) {throw e; });

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
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 2
Last Month 1
Dependencies (3)
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |