mon-cache

0.0.1 • Public • Published

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

Package Sidebar

Install

npm i mon-cache

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • asterisk