Registry / storage / asynchronous-cache

asynchronous-cache

JSON →
library1.1.0jsnpmunverified

Simple asynchronous in-memory cache for deduplicating concurrent calls to async functions. v1.1.0, no dependencies. Key differentiator: caches promises, not just values, so concurrent calls for the same key share a single pending promise, preventing duplicate execution. Supports optional TTL per entry. Minimal API: executeWithCache, delete, clear.

npm install asynchronous-cache
INSTALL
IMPORT
SIG · ASYNCHRONOUS-CACHE
A
asynchronous-cache
storagejavascriptv1.1.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.

Cache
import { Cache } from 'asynchronous-cache'
const Cache = require('asynchronous-cache')
Default export does not exist; named export only. CommonJS users must use require('asynchronous-cache').Cache.
Cache
const { Cache } = require('asynchronous-cache')
const Cache = require('asynchronous-cache').default
CJS destructure or access .Cache property. No default export.
Cache
import { Cache } from 'asynchronous-cache'
import Cache from 'asynchronous-cache'
No default export in ESM.

Creates a cache instance and demonstrates deduplication of concurrent async calls using executeWithCache.

import { Cache } from 'asynchronous-cache'; const cache = new Cache(); let counter = 0; const asyncFn = async () => { return ++counter; }; async function main() { const results = await Promise.all([ cache.executeWithCache('key', asyncFn), cache.executeWithCache('key', asyncFn), ]); console.log(results); // [1, 1] - function executed only once } main();
Debug
Known issues
gotchaWhen using CommonJS, the correct import is `const { Cache } = require('asynchronous-cache')`. Many users mistakenly try `require('asynchronous-cache').default` or a plain `require`.
fix
Use destructured require: const { Cache } = require('asynchronous-cache')
affects: >=1.0.0
gotchaThe `executeWithCache` method expects a function reference (no parentheses). Passing a function call instead will execute it immediately and break caching.
fix
Pass the async function reference: cache.executeWithCache('key', myFn), not cache.executeWithCache('key', myFn())
affects: >=1.0.0
gotchaCache keys are case-sensitive. Calls with different cases (e.g., 'Key' vs 'key') will not be deduplicated.
fix
Normalize keys to lowercase or a consistent format before calling executeWithCache.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cache is not a constructor
Incorrect import style: using default import when the library only exports a named export.
fix
Use named import: import { Cache } from 'asynchronous-cache'
Error: functionToExecute is not a function
Passing a function call result instead of a function reference to executeWithCache.
fix
Pass the async function without invoking it: cache.executeWithCache('key', asyncFn)
Cannot find module 'asynchronous-cache'
Package not installed or import path is wrong.
fix
Run `npm install asynchronous-cache` and use correct import path 'asynchronous-cache'.
TypeError: require(...) is not a function
Using require('asynchronous-cache') directly without destructuring.
fix
Use const { Cache } = require('asynchronous-cache')
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
40
Resources
asynchronous-cache — npm install asynchronous-cache · libregistry