0.0.1 • Published 9 years ago

mon-cache v0.0.1

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

mon-cache

mon-cache is mongoose cache to redis, memcached, or lru-cache. This utilizes the npm modules cache-client.

Initialization

lru-cache

options = {
  store: "memory"
};

require('mon-cache')(mongoose, options);

redis

options = {
  store: "redis",
  port:6379,
  host:"127.0.0.1",
  auth:"password",  // optional
  select_db: 0      // optional, default is 0
};

require('mon-cache')(mongoose, options);

memcached

options = {
  store: "memcached",
  host:"localhost:11211"
};

require('mon-cache')(mongoose, options);

additional options

options = {
  cache: false, // global option to disable caching
  ttl: 60,      // global option to set ttl(sec), default is 60 sec
  debug: true	// print logs for debug
};

Usage

Enable cache with ttl in options. If you don't set ttl, default ttl is 60 sec.

MyModel.find({ ... })
  .cache()
  .exec(function(err, result) { ... });

or

query.cache(true)      // can explicit enable (or disable) caching
query.cache(10)        // enable caching with 10 sec ttl
query.cache(true, 10)  // enable caching with 10 sec ttl

##Contact

  • email: asterisk@makeus.com