Registry / storage / zb-promise-cache

zb-promise-cache

JSON →
library1.0.1jsnpmunverified

A simple Node.js cache object that wraps a promise-returning function and caches the resolved value for a configurable TTL. Version 1.0.1 (latest) with no active development. Uses an LRU cache under the hood with configurable max size and max age. Useful for memoizing async operations like API calls or database queries. Minimal API with get, set, and clear methods. Limited documentation, no TypeScript types, CommonJS only.

npm install zb-promise-cache
INSTALL
IMPORT
SIG · ZB-PROMISE-CACHE
Z
zb-promise-cache
storagejavascriptv1.0.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.

default
const PromiseCache = require('zb-promise-cache');
import PromiseCache from 'zb-promise-cache';
Package is CommonJS-only, no ESM exports.
default
const PromiseCache = require('zb-promise-cache');
const { PromiseCache } = require('zb-promise-cache');
The package exports a single constructor function, not a named export.

Demonstrates creating a PromiseCache instance with options, using get() to fetch/cache, and clear() to reset.

const PromiseCache = require('zb-promise-cache'); const fetchData = (id) => Promise.resolve(`data for ${id}`); const cache = new PromiseCache(fetchData, { max: 100, maxAge: 60000 // 60 seconds }); cache.get('mykey', [42]) .then(val => { console.log(val); // 'data for 42' // Subsequent calls with same key return cached value return cache.get('mykey', [42]); }) .then(val => { console.log(val); // 'data for 42' (from cache) cache.clear(); // Clear all entries }) .catch(err => console.error(err));
Debug
Known issues
gotchaThe 'get' method's cache key is the first argument; params are passed to the promise function ONLY on cache miss. Subsequent calls with different params but same key return the original cached value.
fix
Use unique cache keys per unique input, or handle cache invalidation manually.
affects: >=1.0.0
gotchaThe 'get' method expects params as an array. If you pass a single value not wrapped in an array, it will be interpreted as the params array (spread incorrectly).
fix
Always wrap params in an array: cache.get('key', [value]) even for single argument.
affects: >=1.0.0
deprecatedPackage uses CommonJS; no ESM support. Importing via ES module syntax will fail.
fix
Use require() or use a dynamic import with createRequire.
affects: >=1.0.0
gotchaNo TypeScript definitions available. Using in TypeScript project requires manual declaration or any casts.
fix
Add a custom .d.ts file or use @ts-ignore.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: PromiseCache is not a constructor
Importing package incorrectly as an ES module default import instead of CommonJS require.
fix
Use const PromiseCache = require('zb-promise-cache');
TypeError: cache.get is not a function
Creating instance without 'new' keyword or mis-importing package.
fix
Use const cache = new PromiseCache(fn, opts);
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
lru-cacherequiredUsed internally for caching mechanism
Agent activity
30 hits · last 30 days
node
26
Amazon
1
Resources
zb-promise-cache — npm install zb-promise-cache · libregistry