Registry / storage / buffering-cache

buffering-cache

JSON →
library2.2.1jsnpmunverified

Node.js cache wrapper that asynchronously refreshes cached entries to minimize cache misses and prevent staleness. Current version 2.2.1 releases maintain a steady cadence. Requires ioredis for Redis backend and optionally supports multi-level caching with lru-cache for local memory. Key differentiator: proactive buffer-based refresh strategy rather than passive expiry, keeping hot data fresh with zero additional latency.

npm install buffering-cache
INSTALL
IMPORT
SIG · BUFFERING-CACHE
B
buffering-cache
storagejavascriptv2.2.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.

BufferingCache
const BufferingCache = require('buffering-cache')
import BufferingCache from 'buffering-cache'
This package is CommonJS only; ESM import may fail or require .default access
BufferingCache
const { BufferingCache } = require('buffering-cache')
const { bufferingCache } = require('buffering-cache')
Named export is not supported; only default export
New instance with options
new (require('buffering-cache'))({ redisClient, ttlMsec: 5000 })
require('buffering-cache').BufferingCache({ redisClient })
BufferingCache is a constructor. Must use new and provide at least redisClient and ttlMsec options

Creates a BufferingCache instance with Redis and optional local cache, wraps a function to be cached, then calls it.

const BufferingCache = require('buffering-cache'); const Redis = require('ioredis'); const rp = require('request-promise'); const bufferingCache = new BufferingCache({ redisClient: new Redis({ host: process.env.REDIS_HOST ?? 'localhost', port: 6379, db: 0 }), ttlMsec: 5000, bufferTtlMsec: 2500, localCacheSize: 100, localTtlMsec: 500 }); const fetchData = () => rp('http://example.com'); const wrapped = bufferingCache.wrapFunction(fetchData); wrapped().then(result => { console.log('Result:', result); }).catch(err => { console.error('Error:', err); });
Debug
Known issues
gotchaMissing redisClient option will cause runtime error: Cannot read property 'get' of undefined
fix
Always provide a valid ioredis client as the 'redisClient' option.
affects: >=0.0.0
gotchattlMsec must be a number >= 0, otherwise: AssertionError [ERR_ASSERTION]: ttlMsec must be a number gte 0
fix
Ensure ttlMsec is a positive number (e.g., 5000).
affects: >=0.0.0
gotchabufferTtlMsec must be > 0 and < ttlMsec, otherwise: RangeError: bufferTtlMsec must be greater than 0 and less than ttlMsec
fix
Set bufferTtlMsec to a value between 1 and ttlMsec-1, or omit to use default (ttlMsec/2).
affects: >=0.0.0
gotchalocalCacheSize must be a number >= 0, otherwise: AssertionError [ERR_ASSERTION]: localCacheSize must be a number gte 0
fix
Set localCacheSize to 0 (default) or a positive integer.
affects: >=0.0.0
gotchaUsing ES module import syntax will not work: TypeError: buffering_cache_1.default is not a constructor
fix
Use CommonJS require() instead of import.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'get' of undefined
BufferingCache was instantiated without redisClient option or redisClient is undefined.
fix
Ensure you pass a valid ioredis instance: new BufferingCache({ redisClient: new Redis(/*...*/), ... })
AssertionError [ERR_ASSERTION]: ttlMsec must be a number gte 0
ttlMsec option missing or not a non-negative number.
fix
Provide ttlMsec as a number >= 0 in the configuration object.
RangeError: bufferTtlMsec must be greater than 0 and less than ttlMsec
bufferTtlMsec is either <=0 or >= ttlMsec.
fix
Set bufferTtlMsec to a value between 1 and ttlMsec-1, or omit to use default.
TypeError: buffering_cache_1.default is not a constructor
Using ES module import (import BufferingCache from 'buffering-cache') instead of CommonJS require.
fix
Use const BufferingCache = require('buffering-cache');
Upgrade
Version history
2.2.1latest on npm
Audit
Dependencies
ioredisrequiredRedis client required for remote cache
lru-cacheoptionalLocal memory cache when multi-level caching is enabled
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
buffering-cache — npm install buffering-cache · libregistry