{"id":44178,"library":"abortable-promise-cache","title":"AbortablePromiseCache","description":"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.","status":"active","version":"1.5.0","language":"javascript","source_language":"en","source_url":"https://github.com/rbuels/abortable-promise-cache","tags":["javascript"],"install":[{"cmd":"npm install abortable-promise-cache","lang":"bash","label":"npm"},{"cmd":"yarn add abortable-promise-cache","lang":"bash","label":"yarn"},{"cmd":"pnpm add abortable-promise-cache","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"recommended backing cache; any cache adapter with get/set/delete/keys works","package":"quick-lru","optional":true}],"imports":[{"note":"Default export; named export in CJS is not available. Use default import ESM or default require.","wrong":"const { AbortablePromiseCache } = require('abortable-promise-cache')","symbol":"AbortablePromiseCache","correct":"import AbortablePromiseCache from 'abortable-promise-cache'"},{"note":"In CJS, the default export is under .default. Node >=6 supports require, but .default is needed for default export.","wrong":"const AbortablePromiseCache = require('abortable-promise-cache')","symbol":"default","correct":"const AbortablePromiseCache = require('abortable-promise-cache').default"},{"note":"The package does not export TypeScript types. You must define fill callback signature manually.","wrong":"import { FillCallback } from 'abortable-promise-cache'","symbol":"FillCallback","correct":"No type export; define inline: async (data: any, signal: AbortSignal) => any"}],"quickstart":{"code":"import AbortablePromiseCache from 'abortable-promise-cache';\nimport QuickLRU from 'quick-lru';\n\nconst cache = new AbortablePromiseCache({\n  cache: new QuickLRU({ maxSize: 1000 }),\n  async fill(requestData, abortSignal) {\n    // Simulate long-running task that respects abort signal\n    return new Promise((resolve, reject) => {\n      const timeout = setTimeout(() => resolve('done'), 1000);\n      abortSignal.addEventListener('abort', () => {\n        clearTimeout(timeout);\n        reject(new Error('Aborted'));\n      });\n    });\n  }\n});\n\nasync function example() {\n  const controller = new AbortController();\n  const result = await cache.get('key', { some: 'data' }, controller.signal);\n  console.log(result);\n}\nexample();","lang":"javascript","description":"Creates a cache with a fill function that supports abort, then performs a cached get with an AbortController signal."},"warnings":[{"fix":"In your fill function, listen to abortSignal and cancel your async operation accordingly.","message":"The fill callback must respect the abort signal; otherwise aborting has no effect on ongoing work.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your cache adapter has a keys() method that returns an iterator. Use quick-lru or write an adapter.","message":"The backing cache must implement get, set, delete, and keys methods exactly. Missing keys() will cause runtime error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass plain object options; do not reuse options object with other instances without cloning.","message":"In v1.0.0, the constructor required 'fill' and 'cache' properties. This has not changed, but potential misuse if constructor args are mutated.","severity":"breaking","affected_versions":"1.0.0"}],"env_vars":null,"search_vec":"'6':47 'abort':27,37 'abortablepromisecach':1 'abortcontroller/abortsignal':3 'aborting/cancelling':31 'add':2 'allow':23 'async':9 'automat':30 'back':41 'cach':7,21,42 'cadenc':16 'consum':36 'differenti':17 'fill':32 'get/set/delete/keys':44 'implement':43 'javascript':48 'low':14 'node':46 'per':25 'per-request':24 'promis':20 'releas':15 'request':10,26,33 'requir':45 'semant':4 'signal':28 'simpl':19 'stabl':13 'v1.5.0':11 'work':38","created_at":"2026-06-07T12:48:51.192741+00:00","updated_at":"2026-06-07T12:48:51.192741+00:00","problems":[{"fix":"Use a cache like quick-lru that implements keys(), or create an adapter with a keys method returning an iterator.","cause":"The backing cache provided does not have a keys() method.","error":"TypeError: cache.keys is not a function"},{"fix":"Run `npm install abortable-promise-cache --save` and ensure import/require uses correct syntax (see imports).","cause":"Package not installed or incorrect import path.","error":"Module not found: Can't resolve 'abortable-promise-cache'"},{"fix":"Use `const AbortablePromiseCache = require('abortable-promise-cache').default;`","cause":"In CommonJS, using require('abortable-promise-cache') without .default.","error":"AbortablePromiseCache is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/rbuels/abortable-promise-cache","github":"https://github.com/rbuels/abortable-promise-cache","docs":null,"changelog":null,"pypi":null,"npm":"abortable-promise-cache","openapi_spec":null,"status_page":null,"smithery":null,"categories":["storage","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}