Skip to content

ewinds/mongoose-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM

#About Best Performance Mongoose caching module that works exactly how you would expect it to, with the latest version of Mongoose.

#Websites Use

  • viraldeal.net
  • codek.tv
  • viralr.tv

Installation

Install via NPM

npm install mongoose-redis

Example Usage

var mongoose = require('mongoose');
var MongooseCache = require('mongoose-redis');

Config mongoose-redis cache

var cache = MongooseCache(mongoose, {port: 6379, host: 'localhost'});

Config with compress, with this configuration, the data will be compressed before saving on Redis

var cache = MongooseCache(mongoose, {port: 6379, host: 'localhost', compress: true});
Post.find({ stt: 1 }).sort({ crt: -1 })
.limit(30)
.cache(120) // cache 120 seconds
.select({ tl: 1, lth:1, views:1, img: 1, slug: 1})
.exec(function(err, docs) {
  // do something
});

Post.find({ stt: 1 }).sort({ crt: -1 })
.limit(30)
.reCache(120) // cache 120 seconds and save again on redis
.select({ tl: 1, lth:1, views:1, img: 1, slug: 1})
.exec(function(err, docs) {
  // do something
});

You can also pass a custom key into the .cache() method, which you can then use later to clear the cached content.

app.get('/detail/:id', function(req, res) {
    var _id = req.params.id;  
      Post.findOne({ slug: _id, stt: 1 })
            .cache(120, _id) // custom cache key by id
            .exec(function(err, doc) {
              return res.render("info", { info: doc, title: doc.tl, image: doc.img, description: doc.desc });
            });       
});

Continue updating...

About

a Fork of original mongoose-redis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published