Registry / storage / cache-service-node-cache

cache-service-node-cache

JSON →
library2.0.0jsnpmunverified

A node-cache plugin for cache-service and standalone node-cache wrapper, version 2.0.0. Provides a robust caching layer with background refresh support, configurable expiration, and verbose logging. Designed to work seamlessly with cache-service and superagent-cache. Key differentiators: excellent mset() implementation allowing per-key, per-call, and per-instance expirations; public access to the underlying node-cache instance. Released as a stable package with node-cache 4.x as a peer dependency.

npm install cache-service-node-cache
INSTALL
IMPORT
SIG · CACHE-SERVICE-NODE
C
cache-service-node-cache
storagejavascriptv2.0.0
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.

default
import csNodeCache from 'cache-service-node-cache'
const csNodeCache = require('cache-service-node-cache').default
The module exports a single constructor function for the cache module. Use default import if using ESM, or require() for CommonJS.
constructor
const nodeCache = new csNodeCache({defaultExpiration: 60})
const nodeCache = csNodeCache({defaultExpiration: 60})
Must be instantiated with 'new' keyword.
API methods: get, mget, set, mset
await nodeCache.set(key, value, expiration)
nodeCache.set(key, value, expiration, callback) without handling callback
Methods are callback-based. Use promisification or wrap with Promise for async/await.

Shows instantiation, setting, getting, and multi-setting with expiration options.

import csNodeCache from 'cache-service-node-cache'; const cacheConfig = { defaultExpiration: 60, verbose: true }; const cache = new csNodeCache(cacheConfig); cache.set('myKey', 'myValue', function(err, response) { if (err) { console.error('Set error:', err); } else { console.log('Set:', response); } }); cache.get('myKey', function(err, response) { if (err) { console.error('Get error:', err); } else { console.log('Get:', response); } }); cache.mset({key1: 'value1', key2: {cacheValue: 'value2', expiration: 120}}, function(err, response) { if (err) { console.error('Mset error:', err); } else { console.log('Mset:', response); } });
Debug
Known issues
gotchaconstructor requires `new` keyword; omitting it will cause global namespace pollution or errors.
fix
ensure using `new csNodeCache(config)`.
affects: all
gotcha`.set()`'s `refresh` and `callback` parameters are optional but their order matters; passing only a callback as third argument will be interpreted as `expiration` due to overloading.
fix
use explicit object params or always pass `expiration` as a number, then `refresh` as function, then `callback`.
affects: all
gotchaThe `mset()` method expects `obj` with values possibly being strings or objects with `cacheValue` and `expiration`. Passing plain string values sets them without custom expiration.
fix
check mset documentation for the correct object shape.
affects: all
breakingpeer dependency node-cache must be >=2.1.1; installed version must match 4.x for this package version.
fix
ensure package.json includes `"node-cache": "4.x"`.
affects: 2.x
deprecatedcallback-based API; no Promise or async/await support out-of-box.
fix
wrap in Promise manually or use promisify.
affects: all
Errors
Common errors & fixes
TypeError: csNodeCache is not a constructor
imported incorrectly, e.g., using named import instead of default, or forgot `new`.
fix
use `import csNodeCache from 'cache-service-node-cache'` and `new csNodeCache()`.
Error: node-cache is not installed
missing peer dependency.
fix
run `npm install node-cache` and ensure version satisfies peer dependency.
TypeError: callback is not a function
calling .get() or .set() without providing a callback function.
fix
always provide a callback function, i.e., `cache.get('key', (err, val) => { ... })`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
node-cacherequiredpeer dependency wrapping
Agent activity
23 hits · last 30 days
node
21
Resources
cache-service-node-cache — npm install cache-service-node-cache · libregistry