An asynchronous caching library with built-in deduplication, ensuring each resource is fetched only once concurrently. Version 3.4.0 is the latest stable, actively maintained. It supports memory and Redis storage backends, with optional TTL, stale-while-revalidate, invalidation, and custom serialization via transformers. Differentiators include automatic deduplication of in-flight requests, safe key serialization via safe-stable-stringify, and seamless integration with GraphQL and other async contexts.
npm install async-cache-dedupeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a memory cache with 5 second TTL and stale window, defines an async function, and calls it with deduplication.
Replace `import createCache from 'async-cache-dedupe'` with `import { createCache } from 'async-cache-dedupe'`. For CommonJS, use `const { createCache } = require('async-cache-dedupe')`.Move per-function TTL/stale options to the `define` call: `cache.define('fn', { ttl: 10 }, async (...args) => {...})`.Use the `log` option in storage configuration with a pino-compatible logger instance.
Update storage config from `{ type: 'redis', client: ... }` to `{ type: 'redis', options: { client: ..., invalidation: ... } }`.Ensure arguments passed to cached functions are immutable or use primitive types for keys.
Install `ioredis` and create a client with `new Redis()`.
Replace `storage.options.size` with `storage.options.max`.
Use `import { createCache } from 'async-cache-dedupe'` or `const { createCache } = require('async-cache-dedupe')`.Set storage object as `{ type: 'memory' }` or `{ type: 'redis', options: { client: ... } }`.Add a valid ioredis client: `{ type: 'redis', options: { client: new (require('ioredis'))() } }`.Ensure `createCache` returns an object and you call `define` on it: `const cache = createCache(...); cache.define(...)`.
Ensure transformer has both `serialize` and `deserialize` functions.