import { LRUCache } from "lru-cache"; export function cached( f: (...args: Args) => Promise, makeKey: (...args: Args) => string, options?: LRUCache.Options, ): (...args: Args) => Promise { const cache = new LRUCache(options || { max: 500 }); return async function (...args: Args): Promise { const key = makeKey(...args); const cached = cache.get(key); if (cached === undefined) { const value = await f(...args); cache.set(key, { value }); return value; } else { return cached.value; } }; }