Registry / storage / exp-asynccache

exp-asynccache

JSON →
library3.2.0jsnpmunverified

An async cache for Node.js (v3.2.0) that provides a lookup function per key with callback and promise support. Released under the ExpressenAB organization. Differentiates from similar libraries like async-cache by not caching errors, always calling the callback asynchronously, and allowing per-key TTL via additional arguments to the resolve function. Uses lru-cache by default but supports any compatible cache interface. Stable maintenance mode; low release cadence.

npm install exp-asynccache
INSTALL
IMPORT
SIG · EXP-ASYNCCACHE
E
exp-asynccache
storagejavascriptv3.2.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.

AsyncCache
var AsyncCache = require('exp-asynccache')
import AsyncCache from 'exp-asynccache'
CommonJS-only; no ESM or named exports. Default export via require.
AsyncCache constructor
new AsyncCache()
AsyncCache() without new
Constructor must be called with 'new'; omitting it may cause errors or unexpected behavior.
cache.lookup callback
cache.lookup('key', function(resolve) { ... }, callback)
cache.lookup('key', resolve, callback)
Second argument must be a function that receives resolve; passing resolve directly causes incorrect behavior.

Demonstrates callback and promise usage of cache.lookup, including per-key TTL.

var AsyncCache = require('exp-asynccache'); var cache = new AsyncCache(); // Callback usage cache.lookup('mykey', function(resolve) { // Simulate async fetch setTimeout(function() { resolve(null, 'cached value'); }, 100); }, function(err, value) { if (err) console.error(err); else console.log(value); // 'cached value' }); // Promise usage var promise = cache.lookup('mykey2', function(resolve) { resolve(null, { data: 42 }); }); promise.then(console.log).catch(console.error); // With custom TTL per key (for lru-cache) cache.lookup('ephemeral', function(resolve) { resolve(null, 'short-lived', 2000); // expires in 2 seconds }, function(err, value) { console.log(value); });
Debug
Known issues
gotchaCache key must include all data used to compute the value
fix
Ensure the cache key encompasses all variables that affect the result, e.g., concatenate name+location for a person lookup.
affects: >=1.0.0
gotchaErrors are not cached; subsequent lookups for same key after an error will re-execute the lookup function
fix
Handle errors in the lookup function by retrying or logging; do not rely on error caching.
affects: >=1.0.0
gotchaCallback is always called asynchronously even if value is resolved synchronously
fix
Do not assume synchronous behavior; always treat callback as async.
affects: >=1.0.0
breakingVersion 2.0.0 removed deprecated callback style where resolve was passed directly
fix
Update lookup calls to use a function that receives resolve instead of passing resolve directly.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: cache.lookup is not a function
AsyncCache module not imported correctly or outdated version without lookup method.
fix
Install latest version: npm install exp-asynccache@3.2.0
TypeError: resolve is not a function
Second argument to lookup is not a function wrapper; likely passed resolve directly.
fix
Wrap resolve in a function: function(resolve) { ... resolve(...) }
Upgrade
Version history
3.2.0latest on npm
Audit
Dependencies
lru-cacheoptionalOptional; default caching strategy. Any compatible cache can be used instead.
Agent activity
28 hits · last 30 days
node
24
Amazon
1
OpenAI (training)
1
Resources
exp-asynccache — npm install exp-asynccache · libregistry