The argument types of the function.
The return type of the function.
The async function to memoize.
Optionaloptions: MemoizeOptionsConfiguration options including custom resolver.
A memoized version of the function with a cache property.
const expensiveOperation = memoize(
async (id: number, token: CancellableToken) => {
await token.sleep(1000);
return fetchUserData(id);
}
);
const handle1 = expensiveOperation(1); // Takes 1 second
const handle2 = expensiveOperation(1); // Returns cached result immediately
// Clear cache
expensiveOperation.cache.clear();
Creates a memoized version of an async function that caches results. Subsequent calls with the same arguments return the cached result instead of re-executing.