Skip to content

withCache

withCache<TData>(fn, __namedParameters): Promise<TData>

Defined in: utils/cache/withCache.ts:61

Returns the result of a given promise, and caches the result for subsequent invocations against a provided cache key.

Also deduplicates concurrent calls — if multiple callers request the same cache key while the promise is pending, they share the same promise.

TData

() => Promise<TData>

WithCacheOptions

Promise<TData>

// First call fetches, subsequent calls return cached data for 30s
const data = await withCache(
() => client.request({ method: "frak_getMerchantInformation" }),
{ cacheKey: "merchantInfo", cacheTime: 30_000 }
);