Appearance
pMemoize
▸ pMemoize(fn, «destructured»?): (...arguments_: any[]) => any
Memoize functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input.
参数
| Name | Type | Description |
|---|---|---|
fn | any | Function to be memoized. |
«destructured» | Object | - |
› cache | undefined | Map<any, any> | - |
› cacheKey | undefined | (__namedParameters: [any]) => any | - |
返回值
fn
▸ (...arguments_): any
参数
| Name | Type |
|---|---|
...arguments_ | any[] |
返回值
any
示例
import {setTimeout as delay} from 'node:timer/promises';
import pMemoize from 'p-memoize';
import got from 'got';
const memoizedGot = pMemoize(got);
await memoizedGot('https://sindresorhus.com');
// This call is cached
await memoizedGot('https://sindresorhus.com');
await delay(2000);
// This call is not cached as the cache has expired
await memoizedGot('https://sindresorhus.com');