@tirke/node-cache-manager-mongodb
v1.8.0
Published
[![npm version](https://badge.fury.io/js/@tirke%2Fnode-cache-manager-mongodb.svg)](https://badge.fury.io/js/@tirke%2Fnode-cache-manager-mongodb)
Downloads
193
Readme
MongoDB store for node cache manager
MongoDB cache store for node-cache-manager. This is a rewrite of v4l3r10/node-cache-manager-mongodb.
Installation
npm install @tirke/node-cache-manager-mongodb
yarn add @tirke/node-cache-manager-mongodb
pnpm add @tirke/node-cache-manager-mongodb
Usage Examples
Init
import { caching } from 'cache-manager'
import { mongoDbStore } from './node-cache-manager-mongodb'
const mongoCache = await caching(mongoDbStore, {
url: 'mongodb://localhost:27017',
mongoConfig: { auth: { password: '<password>', username: '<user>' } },
})
Generic usage
import { caching } from 'cache-manager'
import { mongoDbStore } from './node-cache-manager-mongodb'
const mongoCache = await caching(mongoDbStore, {
url: 'mongodb://localhost:27017',
mongoConfig: { auth: { password: '<password>', username: '<user>' } },
})
await mongoCache.set('foo', 'bar', { ttl: 5 })
const result = await mongoCache.get('foo')
await mongoCache.del('foo')
Custom collection name
import { caching } from 'cache-manager'
import { mongoDbStore } from './node-cache-manager-mongodb'
const mongoCache = await caching(mongoDbStore, {
url: 'mongodb://localhost:27017',
collectionName: 'custom-collection-name',
mongoConfig: { auth: { password: '<password>', username: '<user>' } },
})
Custom database name
import { caching } from 'cache-manager'
import { mongoDbStore } from './node-cache-manager-mongodb'
const mongoCache = await caching(mongoDbStore, {
url: 'mongodb://localhost:27017',
databaseName: 'custom-database-name',
mongoConfig: { auth: { password: '<password>', username: '<user>' } },
})