diff options
Diffstat (limited to 'middleware/cache/item.go')
-rw-r--r-- | middleware/cache/item.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/middleware/cache/item.go b/middleware/cache/item.go index 6a75afdf9..5084bcf1c 100644 --- a/middleware/cache/item.go +++ b/middleware/cache/item.go @@ -3,6 +3,7 @@ package cache import ( "time" + "github.com/coredns/coredns/middleware/cache/freq" "github.com/coredns/coredns/middleware/pkg/response" "github.com/miekg/dns" ) @@ -18,6 +19,8 @@ type item struct { origTTL uint32 stored time.Time + + *freq.Freq } func newItem(m *dns.Msg, d time.Duration) *item { @@ -43,10 +46,12 @@ func newItem(m *dns.Msg, d time.Duration) *item { i.origTTL = uint32(d.Seconds()) i.stored = time.Now().UTC() + i.Freq = new(freq.Freq) + return i } -// toMsg turns i into a message, it tailers the reply to m. +// toMsg turns i into a message, it tailors the reply to m. // The Authoritative bit is always set to 0, because the answer is from the cache. func (i *item) toMsg(m *dns.Msg) *dns.Msg { m1 := new(dns.Msg) @@ -67,9 +72,9 @@ func (i *item) toMsg(m *dns.Msg) *dns.Msg { return m1 } -func (i *item) expired(now time.Time) bool { +func (i *item) ttl(now time.Time) int { ttl := int(i.origTTL) - int(now.UTC().Sub(i.stored).Seconds()) - return ttl < 0 + return ttl } // setMsgTTL sets the ttl on all RRs in all sections. If ttl is smaller than minTTL |