Registry / storage / cache-manager-node-cache

cache-manager-node-cache

JSON →
library1.1.1jsnpmunverified

A memory cache store for cache-manager using node-cache. Version 1.1.1 is current. Provides an alternative to the built-in LRU store with support for TTL and refreshThreshold. Easy drop-in replacement. Published on npm, maintained on GitHub. Suitable for Node.js applications using cache-manager. Not actively maintained, last update September 2019.

npm install cache-manager-node-cache
INSTALL
IMPORT
SIG · CACHE-MANAGER-NODE
C
cache-manager-node-cache
storagejavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NodeCacheStore
import NodeCacheStore from 'cache-manager-node-cache'
const { NodeCacheStore } = require('cache-manager-node-cache')
Default export only; not a named export. Works with both ESM and CJS.
cacheManager
import cacheManager from 'cache-manager'
Required as a separate package to use the store.
node-cache
import NodeCache from 'node-cache'
Not needed directly unless customizing node-cache instance.

Shows how to set up and use the node-cache store with cache-manager including TTL and refreshThreshold.

import NodeCacheStore from 'cache-manager-node-cache'; import cacheManager from 'cache-manager'; const memoryCache = cacheManager.caching({ store: NodeCacheStore, ttl: 60, // seconds refreshThreshold: 30 // refresh if accessed within 30s of TTL }); async function main() { await memoryCache.set('key', 'value'); const val = await memoryCache.get('key'); console.log(val); // 'value' await memoryCache.del('key'); } main();
Debug
Known issues
gotchaThe store does not support clusters; node-cache is in-process memory only.
fix
Use a distributed cache store like Redis for multi-process environments.
affects: >=1.0.0
gotchaDefault export is an object, not a class; using `new NodeCacheStore()` will fail.
fix
Pass the default export directly as `store: NodeCacheStore`.
affects: >=1.0.0
deprecatedThe package has not been updated since September 2019; no active maintenance.
fix
Consider using cache-manager's built-in memory store or switch to a maintained alternative.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: NodeCacheStore is not a constructor
Using `new NodeCacheStore()` instead of passing as object
fix
Use `store: NodeCacheStore` in the config object, not `new`.
Error: store must be an object of type { get, set, ... }
Passing an instance instead of the store constructor's result
fix
Pass the imported default export directly as `store: NodeCacheStore`.
Cannot find module 'cache-manager'
cache-manager not installed as a dependency
fix
Run `npm install cache-manager` along with cache-manager-node-cache.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
cache-managerrequiredpeer dependency; this package is a store for cache-manager
node-cacherequiredunderlying caching library
Agent activity
27 hits · last 30 days
node
25
Resources
cache-manager-node-cache — npm install cache-manager-node-cache · libregistry