blugavere / mongoose-model-cache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Coverage Status NPM Downloads NPM version

Mongoose Model Cache

Collection level batching and caching for mongoose queries, powered by es6 proxies.

Usage

import mongoose from 'mongoose';
import modelCache from 'mongoose-model-cache';

// configure a schema somewhere
const schema = new mongoose.Schema({
  name: { type: String }
});

// register it to mongoose
const Cat = mongoose.model('Cat', schema);

const CatCache = modelCache(Cat, {
    ttl: 5000 // cache for 5 seconds
});

(async () => {
    const cats = await CatCache.find();
    console.log(cats);
})();

// optionally, replace global instance
mongoose.models['Cat'] = CatCache;

Supported Methods:

  • find
  • findOne
  • findById
  • count

About


Languages

Language:TypeScript 100.0%