0.1.13 • Published 10 years ago

express-cache-tool v0.1.13

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

How to use

var CacheTool = require('express-cache-tool');
var cache = new CacheTool.Cache({
    duplicate: false, //default false, if true, will create a no expiration cache for this key
    expired: null //default null, ms
}, [debug], [sync_key]);
//sync_key defaul '_cacheSync', if you want to refresh the cache, you can add ?{sync_key}=1 in url

cache.use(CacheTool.MemoryCache);

var test_cache1 = cache.set('key1', {duplicate: true, expired: 60000}, [alias]);

app.get('/', test_cache1, function(req, res, next){
  //if define alias, use req.cache.alias
  //else use req.cache
  req.cache.get_or_create(function(fail, done){
    //if duplicate set true and the asyncFunc is fail, it will get the cache from duplicate
    asyncFunc().then(done).catch(fail);
  }).then(function(result){
    res.json(result);
  }).catch(next);
});

You also can set multiple cache in one route, like app.get('/', test_cache1, test_cache2, function(req, res, next){})

Cache scheme in express-cache-tool

  1. MemoryCache - cache.use(MemoryCache)
  2. FileCache - cache.use(FileCache)
  3. RedisCache - base on ioredis

Use RedisCache

redisCache = RedisCache({
    conf: 'host:port', //or use cluster [{host: host, port: port}, ...]
    db: 0
}, [redis], [prefix]);
//if set redis and the first parameter is null, use a already exists redis connet, must be base on ioredis

cache.use(redisCache);

Custom cache scheme

var scheme = {
    set: function(key, value, expired){
        //return promise
    },
    get: function(key){
        //return promise
    }
}
cache.use(scheme);
0.1.13

10 years ago

0.1.12

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago