From b3ec895c502b62d7aa959f1398bf4e8e052497b6 Mon Sep 17 00:00:00 2001 From: Ryan Salazar Date: Thu, 28 May 2026 14:31:49 +0000 Subject: [PATCH] =?UTF-8?q?lib/ads:=20drop=20in-process=20cache=205min=20?= =?UTF-8?q?=E2=86=92=2030s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- src/lib/ads.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/ads.ts b/src/lib/ads.ts index 0b8ae32..de6519f 100644 --- a/src/lib/ads.ts +++ b/src/lib/ads.ts @@ -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 | null = null; @@ -94,7 +98,7 @@ interface RmpBanner { async function fetchPlacement(size: Ad["size"]): Promise { 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[] };