import { prisma } from "@/module/_global"; const CACHE_TTL_MS = 60_000; let apiKeyCache: Set = new Set(); let cacheExpiresAt = 0; export async function isValidApiKey(incoming: string): Promise { const now = Date.now(); if (now > cacheExpiresAt) { const rows = await prisma.apiKey.findMany({ where: { isActive: true }, select: { key: true } }); apiKeyCache = new Set(rows.map((r) => r.key)); cacheExpiresAt = now + CACHE_TTL_MS; } return apiKeyCache.has(incoming); }