Skip to content

Function.memoizeAsync

github-actions[bot] edited this page Nov 18, 2026 · 13 revisions

umt / memoizeAsync

Function: memoizeAsync()

memoizeAsync<A, R, K>(function_, options?): ((...arguments_) => Promise<R>) & object

Defined in: Async/memoizeAsync.ts:23

Creates a memoized version of an async function. Concurrent calls that share a key reuse a single in-flight promise, and resolved values are cached in a Map keyed by the first argument (or a custom resolver). Rejected calls are not cached, so the next call with the same key invokes the function again.

Type Parameters

A

A extends unknown[]

Argument tuple type

R

R

Resolved value type

K

K = unknown

Cache key type

Parameters

function_

(...arguments_) => Promise<R>

The async function to memoize

options?

Configuration for cache behavior

maxSize?

number

Maximum cache entries before evicting the oldest

resolver?

(...arguments_) => K

Custom key resolver function

Returns

((...arguments_) => Promise<R>) & object

The memoized async function with an exposed cache of resolved values

Example

const fetchUser = memoizeAsync((id: number) => api.getUser(id));
const [a, b] = await Promise.all([fetchUser(1), fetchUser(1)]);
// api.getUser is invoked once; a === b
fetchUser.cache.size; // 1

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally