mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
plugin/cache: cap TTL on first answer (#1092)
Cache would let the first response through and would then cap subsequent ones to whatever the cache duration was. This would lead to huge drops in TTL values: 3600 -> 20 for instance, which is not only bad, but can mess up your careful TTL planning business. This PR fixes that and applies the cache duration to all replies. As a bonus I could remove a time.Sleep() from the cache test and just check for the cache duration as the TTL on the reply. Fixes #1038
This commit is contained in:
13
plugin/cache/cache.go
vendored
13
plugin/cache/cache.go
vendored
@@ -117,6 +117,19 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Apply capped TTL to this reply to avoid jarring TTL experience 1799 -> 8 (e.g.)
|
||||
ttl := uint32(duration.Seconds())
|
||||
for i := range res.Answer {
|
||||
res.Answer[i].Header().Ttl = ttl
|
||||
}
|
||||
for i := range res.Ns {
|
||||
res.Ns[i].Header().Ttl = ttl
|
||||
}
|
||||
for i := range res.Extra {
|
||||
if res.Extra[i].Header().Rrtype != dns.TypeOPT {
|
||||
res.Extra[i].Header().Ttl = ttl
|
||||
}
|
||||
}
|
||||
return w.ResponseWriter.WriteMsg(res)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user