Registry / database / cluster-node-cache

cluster-node-cache

JSON →
library0.1.5jsnpmunverified

A cluster-aware wrapper for node-cache that synchronizes an in-memory cache across Node.js cluster workers. Current version 0.1.5 (last release April 2018) wraps node-cache v1.x and does not support v2.0. Designed for simple, fast internal caching without external dependencies like Redis. The main differentiator is transparent cache synchronization in clustered Node.js applications, using IPC between master and worker processes. The API mirrors node-cache but returns Promises (or callbacks) for all operations. Note: this package is in maintenance mode and has limited TTL and checkperiod options compared to node-cache v2.

npm install cluster-node-cache
INSTALL
IMPORT
SIG · CLUSTER-NODE-CACHE
C
cluster-node-cache
databasejavascriptv0.1.5
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
var myCache = require('cluster-node-cache')(cluster);
var myCache = require('cluster-node-cache');
The module exports a function that must be called with the cluster object. It does not export a class or constructor.
default (with options)
var myCache = require('cluster-node-cache')(cluster, { stdTTL: 100, checkperiod: 900 });
var myCache = new require('cluster-node-cache')(cluster, options);
Options are passed as the second argument. Do not use 'new'; the factory function returns a cache instance.
set
myCache.set('key', value, ttl).then(function(result){ ... });
myCache.set('key', value);
set returns a Promise (or callback). If you omit ttl, the default TTL from options is used. Always handle errors via result.err.

Shows basic initialization with cluster module and set/get in both master and worker processes.

var cluster = require('cluster'); var myCache = require('cluster-node-cache')(cluster); // In a clustered app: if (cluster.isMaster) { cluster.fork(); // Master can use cache normally myCache.set('foo', 'bar').then(function(result) { console.log(result.success); // true }); } else { // Worker also has same cache content myCache.get('foo').then(function(result) { console.log(result.value); // 'bar' }); }
Debug
Known issues
breakingDoes NOT support node-cache v2.x. Only compatible with node-cache v1.x. If you install the latest node-cache (v2+), the wrapper will break.
fix
Pin node-cache to v1.1.0 or earlier in your package.json: "node-cache": "~1.1.0".
affects: >=0.1.5
gotchaAll methods return Promises, not synchronous values. This differs from node-cache which has both sync and async APIs. Forgetting to handle the promise will cause errors.
fix
Use .then() or async/await to access results. Check result.err for errors.
affects: >=0.1.0
gotchaThe cache instance must be created after the cluster module has been required but before forking. Initializing inside a worker after fork may lead to missing IPC communication.
fix
Initialize cache in the master process or at the top level of the entry point before any cluster.fork() calls.
affects: >=0.1.0
deprecatedThe 'continuation-local-storage' package is deprecated and no longer maintained. Using CLS with this package is discouraged.
fix
Avoid using the CLS option. If you need context propagation, consider alternatives like async_hooks.
affects: >=0.1.0
gotchaThe 'get' method with a single key returns an object with a 'value' property containing { key: value }. This differs from node-cache which returns the value directly.
fix
Access the cached value via result.value[key] or iterate over result.value.
affects: >=0.1.0
Errors
Common errors & fixes
UnhandledPromiseRejectionWarning: TypeError: myCache.get is not a function
Forgetting to call the factory function with cluster; require('cluster-node-cache') returns a function, not a cache instance.
fix
Replace `require('cluster-node-cache')` with `require('cluster-node-cache')(cluster)`.
Error: node-cache version 2.x is not supported by cluster-node-cache
Installing node-cache v2 which introduced breaking changes not handled by this wrapper.
fix
Downgrade node-cache to v1.x: `npm install node-cache@~1.1.0`.
TypeError: Cannot read property 'on' of undefined
The cluster object passed to the factory is undefined or not the cluster module.
fix
Ensure `var cluster = require('cluster');` is called before the factory invocation.
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies
node-cacherequiredCore caching library; cluster-node-cache wraps node-cache v1.x. Does not support node-cache v2.
continuation-local-storageoptionalOptional dependency for CLS namespace support; not required for basic usage.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
cluster-node-cache — npm install cluster-node-cache · libregistry