Registry / storage / await-cache

await-cache

JSON →
library1.0.2jsnpmunverified

A lightweight promise-based cache for async functions with optional LRU eviction and configurable TTL. Current stable version is 1.0.2, released in 2018 with no recent updates. Key differentiators: simple API wrapping any async function, supports LRU via maxSize option, custom argument serialization. Works with both async and sync functions. Minimal dependencies; suitable for Node.js and browser environments.

npm install await-cache
INSTALL
IMPORT
SIG · AWAIT-CACHE
A
await-cache
storagejavascriptv1.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.

cachify
const cachify = require('await-cache')
import cachify from 'await-cache'
Package is CommonJS only; ESM import will fail without bundler transformation.
cachify
import cachify from 'await-cache'
For ESM projects, use bundler or dynamic import as package does not export ES modules natively.
default
const cachify = require('await-cache').default || require('await-cache')
const {} = require('await-cache')
Package exports a single function; destructuring will yield undefined.

Demonstrates wrapping an async fetch function with 5-second TTL cache.

const cachify = require('await-cache'); async function fetchData(url) { const response = await fetch(url); return response.json(); } const cachedFetch = cachify(fetchData, 5000); // cache for 5 seconds async function main() { const data1 = await cachedFetch('https://api.example.com/data'); console.log(data1); const data2 = await cachedFetch('https://api.example.com/data'); // cached console.log(data2); } main().catch(console.error);
Debug
Known issues
gotchaDefault argument serialization uses JSON.stringify. Functions or complex objects as arguments will produce unexpected cache keys.
fix
Provide a custom serialize function in options if using non-serializable arguments.
affects: <2.0
gotchaLRU cache (maxSize option) evicts least recently used entries. If maxAge is also set, expired entries are evicted before LRU eviction.
fix
Understand eviction priorities: expiration first, then LRU.
affects: <2.0
gotchaCache does not handle errors differently; if the wrapped function throws, the error is propagated and not cached.
fix
Wrap function to catch and rethrow if you want error caching behavior.
affects: <2.0
gotchaPackage is not actively maintained; last release 2018. No TypeScript definitions.
fix
Consider alternatives like lru-cache or async-cache-dedupe for active development.
affects: >=1.0
Errors
Common errors & fixes
const { cachify } = require('await-cache'); // Result: cachify is undefined
Destructuring import expects named export; package exports a single function as default.
fix
const cachify = require('await-cache');
import cachify from 'await-cache'; // Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Package is CommonJS; using ESM import directly in Node.js without bundler causes error.
fix
Use dynamic import: const cachify = (await import('await-cache')).default; or use bundler.
cachify(fn, { maxAge: 1000 }).then is not a function
cachify returns a function, not a promise. .then() is called on the returned function.
fix
Cache the result of cachify and call it: const cached = cachify(...); cached().then(...);
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
52 hits · last 30 days
node
44
OpenAI (training)
1
Resources
await-cache — npm install await-cache · libregistry