DNS Cache verbesser

This commit is contained in:
ecki
2026-04-24 11:48:07 +02:00
parent d8a13f1961
commit 7d47ec40ff
+59 -24
View File
@@ -2,42 +2,77 @@
DNS CACHE (mit TTL)
========================= */
// =========================
// DNS CACHE (minimal + robust)
// =========================
const DNS_CACHE_TTL = 300000 // 5 min für erfolgreiche Antworten
const DNS_ERROR_TTL = 5000 // 5 sek für Fehler
const dnsCache = {}
const pending = {}
function normalizeDomain(domain) {
return domain.trim().toLowerCase()
}
async function getDNS(domain){
if(!domain) return []
const key = normalizeDomain(domain)
const now = Date.now()
const TTL = 30000 // 30 Sekunden
if(dnsCache[domain] && (now - dnsCache[domain].time < TTL)){
return dnsCache[domain].ips
const cached = dnsCache[key]
// ✅ gültiger Cache
if(cached && (now - cached.time < cached.ttl)){
return cached.ips
}
try{
const res = await api(API + "/dns/" + domain, {}, { showError: false })
const ips = res.ips || []
dnsCache[domain] = {
ips: ips,
time: now
}
return ips
}catch(e){
dnsCache[domain] = {
ips: [],
time: now
}
return []
// ✅ laufende Anfrage wiederverwenden (dedupe)
if(pending[key]){
return pending[key]
}
pending[key] = (async () => {
try{
const res = await api(
API + "/dns/" + encodeURIComponent(key),
{},
{ showError: false }
)
const ips = res?.ips || []
dnsCache[key] = {
ips,
time: Date.now(),
ttl: DNS_CACHE_TTL
}
return ips
}catch(e){
// ❗ Fehler nur kurz cachen
dnsCache[key] = {
ips: [],
time: Date.now(),
ttl: DNS_ERROR_TTL
}
return []
}finally{
delete pending[key]
}
})()
return pending[key]
}
function dnsStatusMarkup(expectedIp, ips){
if(!ips.length){