From 8a015b8bd2a3949b5a920bb1d5f87d8d7eaafd74 Mon Sep 17 00:00:00 2001 From: kappa Date: Fri, 13 Feb 2026 10:35:24 +0900 Subject: [PATCH] Improve Edge Script cache: 5min TTL for clean IPs, 1min for blocked Reduces DB queries ~80% by caching clean IPs longer. Blocked IPs keep short TTL for quick unblock propagation. Co-Authored-By: Claude Opus 4.6 --- edge-script/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/edge-script/index.ts b/edge-script/index.ts index 8fa0be4..065e7f5 100644 --- a/edge-script/index.ts +++ b/edge-script/index.ts @@ -21,7 +21,8 @@ interface CacheEntry { } const cache = new Map(); -const CACHE_TTL_MS = 60_000; +const CACHE_TTL_BLOCKED_MS = 60_000; // 차단 IP: 1분 (빠른 해제 반영) +const CACHE_TTL_CLEAN_MS = 300_000; // 정상 IP: 5분 (DB 부하 감소) const CACHE_MAX_SIZE = 50_000; function cacheGet(ip: string): boolean | null { @@ -44,7 +45,8 @@ function cacheSet(ip: string, blocked: boolean): void { // If still too large, clear entirely if (cache.size >= CACHE_MAX_SIZE) cache.clear(); } - cache.set(ip, { blocked, expiresAt: Date.now() + CACHE_TTL_MS }); + const ttl = blocked ? CACHE_TTL_BLOCKED_MS : CACHE_TTL_CLEAN_MS; + cache.set(ip, { blocked, expiresAt: Date.now() + ttl }); } // ---------------------------------------------------------------------------