Memoize promise-returning functions with cache expiration and prefetch. v1.2.1 is the latest stable release. Key differentiators: prefetch occurs before expiry to avoid stale data, errors can be cached separately with a shorter TTL, and it supports custom argument serialization. Uses a simple string or JSON-based cache key resolution. Similar to p-memoize but with built-in prefetch.
npm install promise-memoizeNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates memoization of an async function with maxAge and maxErrorAge, including cache clearing.
Pass a custom resolve function or use 'json' serializer for complex arguments.
Set maxErrorAge to a positive number, e.g., 1000 for 1 second.
Type the function as having a clear method, e.g., const memoizedFn: typeof fetchUser & { clear(): void } = memoize(...)Always provide a finite maxAge, or manually call clear() periodically.
Set maxAge to at least a few hundred milliseconds to space out calls.
Change to: const memoize = require('promise-memoize')Run: npm install promise-memoize
Ensure the first argument is a function that returns a promise/thenable.
Use import memoize = require('promise-memoize') or enable esModuleInterop.No dependency data recorded yet.