diff --git a/server.js b/server.js index 70aba62..cf2777a 100644 --- a/server.js +++ b/server.js @@ -553,12 +553,13 @@ const validateResultCache = new Map(); const RESULT_CACHE_TTL = 15 * 60 * 1000; // 15 minutes function resultCacheGet(map, key) { const e = map.get(String(key)); - if (e && (Date.now() - e.ts) < RESULT_CACHE_TTL) return e.data; + const ttl = e && e.ttl ? e.ttl : RESULT_CACHE_TTL; + if (e && (Date.now() - e.ts) < ttl) return e.data; return undefined; } -function resultCacheSet(map, key, data) { +function resultCacheSet(map, key, data, ttlMs) { if (map.size > 2000) map.delete(map.keys().next().value); - map.set(String(key), { data, ts: Date.now() }); + map.set(String(key), { data, ts: Date.now(), ttl: ttlMs || RESULT_CACHE_TTL }); } // ============================================================ @@ -3372,7 +3373,10 @@ const server = http.createServer(async (req, res) => { note: "left=upstream providers, right=downstream customers, uncertain=peers. Sorted by power score.", }, }; - resultCacheSet(validateResultCache, rawAsn, validateResult); + // Cache 0-prefix results only briefly (90s) — they may be due to temporary API failures + // Full results with prefixes are cached for the standard 15 minutes + const validateCacheTTL = allPrefixes.length === 0 ? 90 * 1000 : RESULT_CACHE_TTL; + resultCacheSet(validateResultCache, rawAsn, validateResult, validateCacheTTL); return res.end(JSON.stringify(validateResult, null, 2)); } catch (err) { res.writeHead(500);