mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
[plugin/cache] cache failures (#2720)
* cache failures * use ServerError
This commit is contained in:
5
plugin/cache/cache.go
vendored
5
plugin/cache/cache.go
vendored
@@ -163,6 +163,9 @@ func (w *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||
var duration time.Duration
|
||||
if mt == response.NameError || mt == response.NoData {
|
||||
duration = computeTTL(msgTTL, w.minnttl, w.nttl)
|
||||
} else if mt == response.ServerError {
|
||||
// use default ttl which is 5s
|
||||
duration = minTTL
|
||||
} else {
|
||||
duration = computeTTL(msgTTL, w.minpttl, w.pttl)
|
||||
}
|
||||
@@ -206,7 +209,7 @@ func (w *ResponseWriter) set(m *dns.Msg, key uint64, mt response.Type, duration
|
||||
i := newItem(m, w.now(), duration)
|
||||
w.pcache.Add(key, i)
|
||||
|
||||
case response.NameError, response.NoData:
|
||||
case response.NameError, response.NoData, response.ServerError:
|
||||
i := newItem(m, w.now(), duration)
|
||||
w.ncache.Add(key, i)
|
||||
|
||||
|
||||
28
plugin/cache/cache_test.go
vendored
28
plugin/cache/cache_test.go
vendored
@@ -87,6 +87,34 @@ var cacheTestCases = []cacheTestCase{
|
||||
},
|
||||
shouldCache: true,
|
||||
},
|
||||
{
|
||||
RecursionAvailable: true, Authoritative: false,
|
||||
Case: test.Case{
|
||||
Rcode: dns.RcodeServerFailure,
|
||||
Qname: "example.org.", Qtype: dns.TypeA,
|
||||
Ns: []dns.RR{},
|
||||
},
|
||||
in: test.Case{
|
||||
Rcode: dns.RcodeServerFailure,
|
||||
Qname: "example.org.", Qtype: dns.TypeA,
|
||||
Ns: []dns.RR{},
|
||||
},
|
||||
shouldCache: true,
|
||||
},
|
||||
{
|
||||
RecursionAvailable: true, Authoritative: false,
|
||||
Case: test.Case{
|
||||
Rcode: dns.RcodeNotImplemented,
|
||||
Qname: "example.org.", Qtype: dns.TypeA,
|
||||
Ns: []dns.RR{},
|
||||
},
|
||||
in: test.Case{
|
||||
Rcode: dns.RcodeNotImplemented,
|
||||
Qname: "example.org.", Qtype: dns.TypeA,
|
||||
Ns: []dns.RR{},
|
||||
},
|
||||
shouldCache: true,
|
||||
},
|
||||
{
|
||||
RecursionAvailable: true, Authoritative: true,
|
||||
Case: test.Case{
|
||||
|
||||
Reference in New Issue
Block a user