Add dns cache clearing mechanisms

This commit is contained in:
Daniel
2020-07-16 16:29:25 +02:00
parent c9ba2a939a
commit 53e9d3dd47
4 changed files with 140 additions and 9 deletions

View File

@@ -34,6 +34,11 @@ type RRCache struct {
updated int64 // mutable
}
// ID returns the ID of the RRCache consisting of the domain and question type.
func (rrCache *RRCache) ID() string {
return rrCache.Domain + rrCache.Question.String()
}
// Expired returns whether the record has expired.
func (rrCache *RRCache) Expired() bool {
return rrCache.TTL <= time.Now().Unix()
@@ -70,6 +75,11 @@ func (rrCache *RRCache) Clean(minExpires uint32) {
lowestTTL = minExpires
}
// shorten NXDomain caching
if len(rrCache.Answer) == 0 {
lowestTTL = 10
}
// log.Tracef("lowest TTL is %d", lowestTTL)
rrCache.TTL = time.Now().Unix() + int64(lowestTTL)
}