cache.ts 308 B

12345678
  1. const fetchCache = new Map<string, any>();
  2. export async function cachedFetchJSON(url: string, options?: RequestInit): Promise<any> {
  3. if (fetchCache.has(url))
  4. return fetchCache.get(url);
  5. const response = await fetch(url, options).then((r) => r.json());
  6. fetchCache.set(url, response);
  7. return response;
  8. }