Registry / storage / abortable-promise-cache

abortable-promise-cache

JSON →
library1.5.0jsnpmunverified

Adds AbortController/AbortSignal semantics to a cache of async requests. v1.5.0 is stable, low release cadence. Differentiates from simple promise caches by allowing per-request abort signals and automatically aborting/cancelling fill requests when all consumers abort. Works with any backing cache implementing get/set/delete/keys. Requires Node >=6.

npm install abortable-promise-cache
INSTALL
IMPORT
SIG · ABORTABLE-PROMISE-
A
abortable-promise-cache
storagejavascriptv1.5.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.

AbortablePromiseCache
import AbortablePromiseCache from 'abortable-promise-cache'
const { AbortablePromiseCache } = require('abortable-promise-cache')
Default export; named export in CJS is not available. Use default import ESM or default require.
default
const AbortablePromiseCache = require('abortable-promise-cache').default
const AbortablePromiseCache = require('abortable-promise-cache')
In CJS, the default export is under .default. Node >=6 supports require, but .default is needed for default export.
FillCallback
No type export; define inline: async (data: any, signal: AbortSignal) => any
import { FillCallback } from 'abortable-promise-cache'
The package does not export TypeScript types. You must define fill callback signature manually.

Creates a cache with a fill function that supports abort, then performs a cached get with an AbortController signal.

import AbortablePromiseCache from 'abortable-promise-cache'; import QuickLRU from 'quick-lru'; const cache = new AbortablePromiseCache({ cache: new QuickLRU({ maxSize: 1000 }), async fill(requestData, abortSignal) { // Simulate long-running task that respects abort signal return new Promise((resolve, reject) => { const timeout = setTimeout(() => resolve('done'), 1000); abortSignal.addEventListener('abort', () => { clearTimeout(timeout); reject(new Error('Aborted')); }); }); } }); async function example() { const controller = new AbortController(); const result = await cache.get('key', { some: 'data' }, controller.signal); console.log(result); } example();
Debug
Known issues
gotchaThe fill callback must respect the abort signal; otherwise aborting has no effect on ongoing work.
fix
In your fill function, listen to abortSignal and cancel your async operation accordingly.
affects: >=1.0.0
gotchaThe backing cache must implement get, set, delete, and keys methods exactly. Missing keys() will cause runtime error.
fix
Ensure your cache adapter has a keys() method that returns an iterator. Use quick-lru or write an adapter.
affects: >=1.0.0
breakingIn v1.0.0, the constructor required 'fill' and 'cache' properties. This has not changed, but potential misuse if constructor args are mutated.
fix
Pass plain object options; do not reuse options object with other instances without cloning.
affects: 1.0.0
Errors
Common errors & fixes
TypeError: cache.keys is not a function
The backing cache provided does not have a keys() method.
fix
Use a cache like quick-lru that implements keys(), or create an adapter with a keys method returning an iterator.
Module not found: Can't resolve 'abortable-promise-cache'
Package not installed or incorrect import path.
fix
Run `npm install abortable-promise-cache --save` and ensure import/require uses correct syntax (see imports).
AbortablePromiseCache is not a constructor
In CommonJS, using require('abortable-promise-cache') without .default.
fix
Use `const AbortablePromiseCache = require('abortable-promise-cache').default;`
Upgrade
Version history
1.5.0latest on npm
Audit
Dependencies
quick-lruoptionalrecommended backing cache; any cache adapter with get/set/delete/keys works
Agent activity
59 hits · last 30 days
node
52
OpenAI (training)
1
Resources
abortable-promise-cache — npm install abortable-promise-cache · libregistry