lib/ads: drop in-process cache 5min → 30s

Pairs with advertising-rmp's /api/banners cache shortening so admin
banner uploads appear on the live site in ~60s instead of up to 15min.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ryan Salazar
2026-05-28 14:31:49 +00:00
parent 28c05962ce
commit b3ec895c50

View File

@@ -25,7 +25,11 @@ const SUPABASE_URL = process.env.NEXT_PUBLIC_SUPABASE_URL!;
const SUPABASE_ANON = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!;
const SCHEMA = process.env.NEXT_PUBLIC_SUPABASE_SCHEMA || "bb";
const CACHE_TTL_MS = 5 * 60 * 1000;
// 30s in-process cache so admin uploads show on the site within ~30s.
// The /api/banners endpoint also caps at 30s, so worst-case from upload
// to live is ~60s. Was 5min, which combined with the API + CDN layers
// could push banner updates out to 15 minutes.
const CACHE_TTL_MS = 30 * 1000;
type CacheRow = { rows: Ad[]; loadedAt: number };
let CACHE: CacheRow | null = null;
let REFRESH_IN_FLIGHT: Promise<void> | null = null;
@@ -94,7 +98,7 @@ interface RmpBanner {
async function fetchPlacement(size: Ad["size"]): Promise<Ad[]> {
try {
const res = await fetch(`${RMP_API}/api/banners/${PROPERTY}/${size}`, {
next: { revalidate: 300 },
next: { revalidate: 30 },
});
if (!res.ok) return [];
const data = await res.json() as { banners?: RmpBanner[] };