
Security News
Open VSX Begins Implementing Pre-Publish Security Checks After Repeated Supply Chain Incidents
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.
ts-cache-mongoose
Advanced tools
Cache query and aggregate in mongoose using in-memory or redis
ts-cache-mongoose is a plugin for mongoose
Caching queries is a good way to improve performance of your application
{
"node": "18.x || 20.x || 22.x",
"mongoose": ">=6.6.x || 7.x || 8.x",
}
npm install ts-cache-mongoose
pnpm add ts-cache-mongoose
yarn add ts-cache-mongoose
bun add ts-cache-mongoose
>=6.6.x || 7.x || 8.x to be installed as a peer dependency# For latest mongoose 6
npm install mongoose@6
pnpm add mongoose@6
yarn add mongoose@6
bun add mongoose@6
# For latest mongoose 7
npm install mongoose@7
pnpm add mongoose@7
yarn add mongoose@7
bun add mongoose@7
# For latest mongoose 8
npm install mongoose@8
pnpm add mongoose@8
yarn add mongoose@8
bun add mongoose@8
// On your application startup
import mongoose from 'mongoose'
import cache from 'ts-cache-mongoose'
// In-memory example
const instance = cache.init(mongoose, {
defaultTTL: '60 seconds',
engine: 'memory',
debug: true, // Debug mode enables hit/miss logs in console, not for production use
})
// OR
// Redis example
const instance = cache.init(mongoose, {
defaultTTL: '60 seconds',
engine: 'redis',
engineOptions: {
host: 'localhost',
port: 6379,
},
debug: true, // Debug mode enables hit/miss logs in console, not for production use
})
// Connect to your database
mongoose.connect('mongodb://localhost:27017/my-database')
// Somewhere in your code
const users = await User.find({ role: 'user' }).cache('10 seconds').exec()
// Cache hit
const users = await User.find({ role: 'user' }).cache('10 seconds').exec()
const book = await Book.findById(id).cache('1 hour').exec()
const bookCount = await Book.countDocuments().cache('1 minute').exec()
const authors = await Book.distinct('author').cache('30 seconds').exec()
const books = await Book.aggregate([
{
$match: {
genre: 'fantasy',
},
},
{
$group: {
_id: '$author',
count: { $sum: 1 },
},
},
{
$project: {
_id: 0,
author: '$_id',
count: 1,
},
}
]).cache('1 minute').exec()
// Cache invalidation
// To clear all cache, don't use in production unless you know what you are doing
await instance.clear()
// Instead use custom cache key
const user = await User.findById('61bb4d6a1786e5123d7f4cf1').cache('1 minute', 'some-custom-key').exec()
await instance.clear('some-custom-key')
FAQs
Cache plugin for mongoose Queries and Aggregate (in-memory, redis)
The npm package ts-cache-mongoose receives a total of 1,662 weekly downloads. As such, ts-cache-mongoose popularity was classified as popular.
We found that ts-cache-mongoose demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Following multiple malicious extension incidents, Open VSX outlines new safeguards designed to catch risky uploads earlier.

Research
/Security News
Threat actors compromised four oorzc Open VSX extensions with more than 22,000 downloads, pushing malicious versions that install a staged loader, evade Russian-locale systems, pull C2 from Solana memos, and steal macOS credentials and wallets.

Security News
Lodash 4.17.23 marks a security reset, with maintainers rebuilding governance and infrastructure to support long-term, sustainable maintenance.