Registry / database / hybrid-cache

hybrid-cache

JSON →
library1.0.30jsnpmunverified

hybrid-cache v1.0.30 is a dual-layer caching library for Node.js that combines an in-memory cache (node-cache) with Redis synchronization, focusing on fastest response for basic commands. It allows adding multiple Redis servers and provides methods like set, get, setex, incrby, and flushall. Compared to alternatives like ioredis or node-cache alone, it offers a simple API for hybrid caching with optional Redis sync. Released as a stable package with monthly updates, it supports callbacks and is suitable for applications needing low-latency reads with Redis persistence.

npm install hybrid-cache
INSTALL
IMPORT
SIG · HYBRID-CACHE
H
hybrid-cache
databasejavascriptv1.0.30
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.

HybridCache
const HybridCache = require('hybrid-cache')
const { HybridCache } = require('hybrid-cache')
Default export; no named exports. CommonJS only.
hybridCache instance
const cache = HybridCache()
const cache = new HybridCache()
HybridCache is a factory function, not a constructor.

Initializes hybrid-cache with a local Redis server, sets and retrieves a value.

const HybridCache = require('hybrid-cache'); const hybridCache = HybridCache(); hybridCache.init({ waitingTime: 3, isSyncRedis: true }); hybridCache.addRedisServer({ host: '127.0.0.1', port: '6379' }, (err, result) => { if (err) console.error(err); console.log('Redis server added:', result); }); hybridCache.set('key1', 'value1', (err, result) => { if (err) console.error(err); console.log('Set result:', result); }); hybridCache.get('key1', (err, result) => { if (err) console.error(err); console.log('Get result:', result); });
Debug
Known issues
gotchaHybridCache() must be called without 'new' - it's a factory function.
fix
Use const cache = HybridCache() instead of new HybridCache().
affects: >=1.0.0
deprecatedThe 'waitingTime' and 'retryInterval' options are in seconds but may be confused with milliseconds.
fix
Read docs carefully: waitingTime default is 2 seconds, not milliseconds.
affects: >=1.0.0
gotchaMethods like set, get, setex are asynchronous and expect callbacks; no Promise support.
fix
Use callbacks or promisify: const { promisify } = require('util'); const setAsync = promisify(hybridCache.set.bind(hybridCache));
affects: >=1.0.0
gotchaAccessing hybridCache.Redis or hybridCache.Mem gives direct access to Redis and memory cache, but operations on them bypass local cache synchronization.
fix
Use hybridCache.get/set for unified hybrid behavior; use .Redis or .Mem only when you need to bypass the hybrid layer.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: HybridCache is not a constructor
Using 'new' keyword on factory function HybridCache.
fix
Call HybridCache() without new.
TypeError: hybridCache.set is not a function
Probably imported incorrectly as named export.
fix
Use const HybridCache = require('hybrid-cache'); const cache = HybridCache();
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
Redis server not running or incorrect host/port.
fix
Ensure Redis is running and accessible. Or omit isSyncRedis: true to skip Redis.
Error: init not called or Redis servers not added
Using hybridCache before calling init or addRedisServer.
fix
Call hybridCache.init() before using other methods.
Upgrade
Version history
1.0.30latest on npm
Audit
Dependencies
redisrequiredRedis client used for server communication
node-cacherequiredIn-memory cache layer
Agent activity
6 hits · last 30 days
node
6
Resources
hybrid-cache — npm install hybrid-cache · libregistry