Parse mgmt cache TTL env var once via sync.OnceValue

This commit is contained in:
Viktor Liu
2026-04-22 11:13:00 +02:00
parent 985e37b4d4
commit 236e99af63

View File

@@ -529,14 +529,14 @@ func (m *Resolver) extractDomainsFromServerDomains(serverDomains dnsconfig.Serve
return domains
}
func cacheTTL() time.Duration {
var cacheTTL = sync.OnceValue(func() time.Duration {
if v := os.Getenv(envMgmtCacheTTL); v != "" {
if d, err := time.ParseDuration(v); err == nil && d > 0 {
return d
}
}
return defaultTTL
}
})
// lookupViaChain resolves via the handler chain and rewrites each RR to use
// dnsName as owner and cacheTTL() as TTL, so CNAME-backed domains don't cache