import type { CacheEntry } from "@epic-web/cachified"; import { LRUCache } from "lru-cache"; declare global { // This preserves the LRU cache during development var __lruCache: LRUCache> | undefined; } // biome-ignore lint/suspicious/noAssignInExpressions: trick to only create one export const cache = (global.__lruCache = global.__lruCache ? global.__lruCache : new LRUCache>({ max: 5000 })); export const ttl = (ms: number) => process.env.DISABLE_CACHE === "true" ? 0 : ms; export function syncCached(key: string, getFreshValue: () => T) { if (cache.has(key)) { return cache.get(key) as T; } const value = getFreshValue(); cache.set(key, value as any); return value; } export const IN_MILLISECONDS = { HALF_HOUR: 30 * 60 * 1000, ONE_HOUR: 60 * 60 * 1000, TWO_HOURS: 2 * 60 * 60 * 1000, TWO_DAYS: 2 * 24 * 60 * 60 * 1000, };