/** * Note: the cache map can contain null and false values, so the function must check that the result is strictly not undefined */ export async function getFromCacheRecord(cache: Record, key: Key, runner: (key: Key, ...args: Args) => Promise, ...args: Args): Promise { const result = cache[toKey(key)] return result !== undefined ? result : runner(key, ...args) } export function toKey(object: unknown) { return JSON.stringify(object) }