Define a constant for the TTL of stale responses
This commit is contained in:
parent
2a3e59c4bf
commit
e5608e08cf
|
@ -10,6 +10,8 @@ import (
|
|||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
const StaleResponseTtl = 30 * time.Second
|
||||
|
||||
type CachedResponse struct {
|
||||
expiration time.Time
|
||||
msg dns.Msg
|
||||
|
@ -68,30 +70,35 @@ func (plugin *PluginCache) Reload() error {
|
|||
|
||||
func (plugin *PluginCache) Eval(pluginsState *PluginsState, msg *dns.Msg) error {
|
||||
cacheKey := computeCacheKey(pluginsState, msg)
|
||||
|
||||
cachedResponses.RLock()
|
||||
defer cachedResponses.RUnlock()
|
||||
if cachedResponses.cache == nil {
|
||||
cachedResponses.RUnlock()
|
||||
return nil
|
||||
}
|
||||
cachedAny, ok := cachedResponses.cache.Get(cacheKey)
|
||||
if !ok {
|
||||
cachedResponses.RUnlock()
|
||||
return nil
|
||||
}
|
||||
cached := cachedAny.(CachedResponse)
|
||||
|
||||
expiration := cached.expiration
|
||||
synth := cached.msg.Copy()
|
||||
cachedResponses.RUnlock()
|
||||
|
||||
synth.Id = msg.Id
|
||||
synth.Response = true
|
||||
synth.Compress = true
|
||||
synth.Question = msg.Question
|
||||
|
||||
if time.Now().After(cached.expiration) {
|
||||
updateTTL(synth, time.Now().Add(30 * time.Second))
|
||||
if time.Now().After(expiration) {
|
||||
expiration2 := time.Now().Add(StaleResponseTtl)
|
||||
updateTTL(synth, expiration2)
|
||||
pluginsState.sessionData["stale"] = synth
|
||||
return nil
|
||||
}
|
||||
|
||||
updateTTL(synth, cached.expiration)
|
||||
updateTTL(synth, expiration)
|
||||
|
||||
pluginsState.synthResponse = synth
|
||||
pluginsState.action = PluginsActionSynth
|
||||
|
|
Loading…
Reference in New Issue