Registry / storage / async-cache-promise

async-cache-promise

JSON →
library2.0.2jsnpmunverified

Promise-based caching utility built on top of async-cache. Version 2.0.2 wraps async-cache to provide a promise-returning API. It uses bluebird for advanced promise features and immutable-object-methods for state management. Last updated in 2018, it is in maintenance mode with no recent updates. Key differentiator from similar libraries is its use of generators (co) for asynchronous flows, which is now outdated compared to native async/await.

npm install async-cache-promise
INSTALL
IMPORT
SIG · ASYNC-CACHE-PROMIS
A
async-cache-promise
storagejavascriptv2.0.2
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
import asyncCachePromise from 'async-cache-promise';
const { asyncCachePromise } = require('async-cache-promise');
The default export is a function that creates a cache instance. CommonJS require() returns the function directly, so destructuring is incorrect.
Cache
import asyncCachePromise from 'async-cache-promise'; const cache = asyncCachePromise(options);
import { Cache } from 'async-cache-promise';
There is no named export 'Cache'. The cache instance is created by calling the default export.
setupAsyncCache
import setupAsyncCache from 'async-cache-promise';
const setupAsyncCache = require('async-cache-promise').default;
The default export is the setup function itself. In CommonJS, require('async-cache-promise') returns the function directly; no .default needed.

Demonstrates creating a promise-based cache with a load function using co generators for async flow.

import setupAsyncCache from 'async-cache-promise'; import co from 'co'; co(function*() { const cache = setupAsyncCache({ load: (key) => Promise.resolve(key.toUpperCase()), max: 100 }); const result1 = yield cache.get('hello'); console.log(result1); // HELLO const result2 = yield cache.get('hello'); console.log(result2); // HELLO (cached) });
Debug
Known issues
gotchaThe library uses bluebird promises and generator-based async flow (co). Modern async/await patterns may not be directly compatible without proper wrapping.
fix
Use co to wrap generators or switch to a more modern caching library like cacache or node-cache.
affects: >=2.0.0
deprecatedThe immutable-object-methods dependency is unmaintained and may have security issues.
fix
Consider forking the library to remove this dependency or switch to an alternative.
affects: >=2.0.0
breakingVersion 2.0.0 changed the API from callback-based to promise-based. The default export now returns a promise-based cache instead of a callback-based one.
fix
Upgrade code to use promises and generators/async-await instead of callbacks.
affects: ^2.0.0
gotchaThe function exported is named setupAsyncCache in the documentation but the default export is unnamed; rely on default import.
fix
Always use default import: import setupAsyncCache from 'async-cache-promise'.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'prototype' of undefined
Using a named import like { Cache } which doesn't exist as a named export.
fix
Use default import: import setupAsyncCache from 'async-cache-promise';
ReferenceError: yield is not defined
Using yield outside a generator function without co wrapper.
fix
Wrap code in co(function* () { ... }) or use async/await if you convert the cache API.
Error: Cannot find module 'bluebird'
Missing dependency. The library depends on bluebird but may not install it as a peer dependency.
fix
Run: npm install bluebird
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
async-cacherequiredcore caching logic for async lookups
bluebirdrequiredprovides Promise implementation and utilities
immutable-object-methodsrequiredused internally for immutable object operations
Agent activity
48 hits · last 30 days
node
44
Resources
async-cache-promise — npm install async-cache-promise · libregistry