mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
middleware/cache: cache 0 will be capped at 5 (#408)
* middleware/cache: cache 0 will be capped at 5 cache 0 would return TTL=0 records, up that to the documented minimum of 5 seconds. * middleware/cache: check for 0 TTL Handle 0 TTL differently and return an error, we might need to special case this in the future.
This commit is contained in:
10
middleware/cache/item.go
vendored
10
middleware/cache/item.go
vendored
@@ -63,9 +63,6 @@ func (i *item) toMsg(m *dns.Msg) *dns.Msg {
|
||||
m1.Extra = i.Extra
|
||||
|
||||
ttl := int(i.origTTL) - int(time.Now().UTC().Sub(i.stored).Seconds())
|
||||
if ttl < int(minTTL.Seconds()) {
|
||||
ttl = int(minTTL.Seconds())
|
||||
}
|
||||
setMsgTTL(m1, uint32(ttl))
|
||||
return m1
|
||||
}
|
||||
@@ -75,8 +72,13 @@ func (i *item) expired(now time.Time) bool {
|
||||
return ttl < 0
|
||||
}
|
||||
|
||||
// setMsgTTL sets the ttl on all RRs in all sections.
|
||||
// setMsgTTL sets the ttl on all RRs in all sections. If ttl is smaller than minTTL
|
||||
// that value is used.
|
||||
func setMsgTTL(m *dns.Msg, ttl uint32) {
|
||||
if ttl < minTTL {
|
||||
ttl = minTTL
|
||||
}
|
||||
|
||||
for _, r := range m.Answer {
|
||||
r.Header().Ttl = ttl
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user