Registry / storage / async-cacher

async-cacher

JSON →
library2.0.0jsnpmunverified

A lightweight zero-dependency async cache library for Node.js and browser (current version 2.0.0). It caches async data sources (Promise-returning functions) with configurable TTL, prevents duplicate concurrent requests for the same key (deduplication), and supports forced refresh and per-key clearing. Released in 2016 and still maintained with a small API surface. Compared to alternatives like lru-cache or node-cache, async-cacher focuses solely on async cache coordination with built-in deduplication.

npm install async-cacher
INSTALL
IMPORT
SIG · ASYNC-CACHER
A
async-cacher
storagejavascriptv2.0.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 'async-cacher'
const Cache = require('async-cacher')
Package is ESM-only since v2. Use named import. Default export does not exist.
Cache
import { Cache } from 'async-cacher'
import Cache from 'async-cacher'
Default import is undefined. Must use named import.
Cache
const { Cache } = await import('async-cacher')
const Cache = require('async-cacher')
CommonJS require is not supported. Use dynamic import via async import().

Shows basic usage: instantiate Cache, cache an async data source per key with optional TTL, force refresh, and clear a specific key.

import { Cache } from 'async-cacher'; const cache = new Cache(); const mockDataSource = async (key) => { // Simulate async data fetch return `data for ${key}`; }; async function example() { const result1 = await cache.get({ dataSource: () => mockDataSource('foo'), key: 'foo', }); console.log(result1); // 'data for foo' const result2 = await cache.get({ dataSource: () => mockDataSource('foo'), key: 'foo', millisecondsToLive: 5000, // 5 seconds TTL }); // Force refresh const result3 = await cache.get({ dataSource: () => mockDataSource('foo'), key: 'foo', forceRefresh: true, }); cache.clear({ key: 'foo' }); } example();
Debug
Known issues
breakingIn v2, the package switched to ESM-only. CommonJS require() throws an error.
fix
Use import { Cache } from 'async-cacher' or dynamic import().
affects: >=2.0.0
breakingThe API changed from function-based (v1) to class-based (v2). v1's cache() function is removed.
fix
Replace cache(options) with new Cache() and cache.get(options).
affects: >=2.0.0
gotchaIf dataSource throws, the error propagates and the cache entry is not created; subsequent requests will retry the dataSource.
fix
Handle errors in dataSource or wrap in try-catch around cache.get.
affects: >=1.0.0
gotchaThe cache is in-memory only; does not persist across server restarts or share between processes.
fix
Use a Redis-backed cache for persistent/distributed caching.
affects: >=1.0.0
deprecatedThe package has not received updates since 2021; no known vulnerabilities but unmaintained.
fix
Consider migrating to active alternatives like lru-cache or cache-manager-memory-store.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: async_cacher_1.Cache is not a constructor
Using wrong import (default import instead of named import).
fix
Use import { Cache } from 'async-cacher' instead of import Cache from 'async-cacher'.
Error [ERR_REQUIRE_ESM]: require() of ES Module /.../async-cacher/index.js from ... not supported.
Using CommonJS require() with ESM-only package.
fix
Switch to ESM import or use dynamic import: const { Cache } = await import('async-cacher');
TypeError: cache.get is not a function
Trying to call cache.get() on the old function-based API from v1.
fix
Upgrade to v2 and use new Cache() then cache.get({...}).
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
41 hits · last 30 days
node
36
OpenAI (training)
1
Resources
async-cacher — npm install async-cacher · libregistry