Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-mongoose-cache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-mongoose-cache

cache module for egg-mongoose

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

egg-mongoose-cache

NPM version

Egg's cache plugin based on egg-mongoose and egg-redis for egg framwork

  • egg-mongoose-cache plugin rewrite from cachegoose, increase support for populate.

中文版

Install

$ npm i egg-mongoose-cache --save

Dependencies

egg version

egg-mongoose-cache veregg 2.xegg-mongoose 3.2.x
1.x😁😁
0.x

Dependencies plugins

Usage

// {app_root}/config/plugin.js
exports.mongooseCache = {
  enable: true,
  package: 'egg-mongoose-cache',
};

Configuration

see config/config.default.js for more detail.

  • instanceName: when use egg-redis Multi Clients, set the redis instance name
  • ttl: global default expiration time(second), default: 600
  • keyPrefix: redis Prefix key, defalut: "mc:"

egg-redis Single Client:

exports.mongooseCache = {
  ttl: 600,
  keyPrefix: 'mc:',
}

egg-redis Multi Clients:

exports.mongooseCache = {
  instanceName: 'cache',
  ttl: 300,
  keyPrefix: 'mc:',
}

Example

In controller or service, you can use find/findOne/aggregate to cache data to redis.

Use FindOne/populate, cache 60 second:

let data = await ctx.model.user.findOne({ 'username': 'user1' }).populate('userinfo').cache(60);

Use Find, cache 600 second:

let data = await ctx.model.user.find({}).limit(10).skip(5).cache();

Use Aggregate, cache 60 second and user custom key:

let data = await ctx.model.user.aggregate(myPipelines).cache(60,'myKey');

Questions & Suggestions

Please open an issue egg-mongoose-cache issues.

License

MIT

Keywords

FAQs

Package last updated on 21 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc