plugin/cache: Set min TTL default to zero (#2199)
* set min ttl default to zero * add short TTL test case
This commit is contained in:
parent
8cc8afa96a
commit
4a5641c379
4 changed files with 22 additions and 10 deletions
4
plugin/cache/README.md
vendored
4
plugin/cache/README.md
vendored
|
@ -41,10 +41,10 @@ cache [TTL] [ZONES...] {
|
||||||
* **TTL** and **ZONES** as above.
|
* **TTL** and **ZONES** as above.
|
||||||
* `success`, override the settings for caching successful responses. **CAPACITY** indicates the maximum
|
* `success`, override the settings for caching successful responses. **CAPACITY** indicates the maximum
|
||||||
number of packets we cache before we start evicting (*randomly*). **TTL** overrides the cache maximum TTL.
|
number of packets we cache before we start evicting (*randomly*). **TTL** overrides the cache maximum TTL.
|
||||||
**MINTTL** overrides the cache minimum TTL, which can be useful to limit queries to the backend.
|
**MINTTL** overrides the cache minimum TTL (default 0), which can be useful to limit queries to the backend.
|
||||||
* `denial`, override the settings for caching denial of existence responses. **CAPACITY** indicates the maximum
|
* `denial`, override the settings for caching denial of existence responses. **CAPACITY** indicates the maximum
|
||||||
number of packets we cache before we start evicting (LRU). **TTL** overrides the cache maximum TTL.
|
number of packets we cache before we start evicting (LRU). **TTL** overrides the cache maximum TTL.
|
||||||
**MINTTL** overrides the cache minimum TTL, which can be useful to limit queries to the backend.
|
**MINTTL** overrides the cache minimum TTL (default 0), which can be useful to limit queries to the backend.
|
||||||
There is a third category (`error`) but those responses are never cached.
|
There is a third category (`error`) but those responses are never cached.
|
||||||
* `prefetch` will prefetch popular items when they are about to be expunged from the cache.
|
* `prefetch` will prefetch popular items when they are about to be expunged from the cache.
|
||||||
Popular means **AMOUNT** queries have been seen with no gaps of **DURATION** or more between them.
|
Popular means **AMOUNT** queries have been seen with no gaps of **DURATION** or more between them.
|
||||||
|
|
4
plugin/cache/cache.go
vendored
4
plugin/cache/cache.go
vendored
|
@ -239,9 +239,9 @@ func (w *ResponseWriter) Write(buf []byte) (int, error) {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
maxTTL = dnsutil.MaximumDefaulTTL
|
maxTTL = dnsutil.MaximumDefaulTTL
|
||||||
minTTL = dnsutil.MinimalDefaultTTL
|
minTTL = 0
|
||||||
maxNTTL = dnsutil.MaximumDefaulTTL / 2
|
maxNTTL = dnsutil.MaximumDefaulTTL / 2
|
||||||
minNTTL = dnsutil.MinimalDefaultTTL
|
minNTTL = 0
|
||||||
|
|
||||||
defaultCap = 10000 // default capacity of the cache.
|
defaultCap = 10000 // default capacity of the cache.
|
||||||
|
|
||||||
|
|
|
@ -43,17 +43,28 @@ func TestLookupCache(t *testing.T) {
|
||||||
p := proxy.NewLookup([]string{udp})
|
p := proxy.NewLookup([]string{udp})
|
||||||
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
|
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
|
||||||
|
|
||||||
resp, err := p.Lookup(state, "example.org.", dns.TypeA)
|
t.Run("Long TTL", func(t *testing.T) {
|
||||||
|
testCase(t, state, p, "example.org.", 2, 10)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Short TTL", func(t *testing.T) {
|
||||||
|
testCase(t, state, p, "short.example.org.", 1, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCase(t *testing.T, state request.Request, p proxy.Proxy, name string, expectAnsLen int, expectTTL uint32) {
|
||||||
|
resp, err := p.Lookup(state, name, dns.TypeA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Expected to receive reply, but didn't")
|
t.Fatal("Expected to receive reply, but didn't")
|
||||||
}
|
}
|
||||||
// expect answer section with A record in it
|
|
||||||
if len(resp.Answer) == 0 {
|
if len(resp.Answer) != expectAnsLen {
|
||||||
t.Fatal("Expected to at least one RR in the answer section, got none")
|
t.Fatalf("Expected %v RR in the answer section, got %v.", expectAnsLen, len(resp.Answer))
|
||||||
}
|
}
|
||||||
|
|
||||||
ttl := resp.Answer[0].Header().Ttl
|
ttl := resp.Answer[0].Header().Ttl
|
||||||
if ttl != 10 { // as set in the Corefile
|
if ttl != expectTTL {
|
||||||
t.Errorf("Expected TTL to be %d, got %d", 10, ttl)
|
t.Errorf("Expected TTL to be %d, got %d", expectTTL, ttl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ example.org. IN NS b.iana-servers.net.
|
||||||
example.org. IN NS a.iana-servers.net.
|
example.org. IN NS a.iana-servers.net.
|
||||||
example.org. IN A 127.0.0.1
|
example.org. IN A 127.0.0.1
|
||||||
example.org. IN A 127.0.0.2
|
example.org. IN A 127.0.0.2
|
||||||
|
short.example.org. 1 IN A 127.0.0.3
|
||||||
*.w.example.org. IN TXT "Wildcard"
|
*.w.example.org. IN TXT "Wildcard"
|
||||||
a.b.c.w.example.org. IN TXT "Not a wildcard"
|
a.b.c.w.example.org. IN TXT "Not a wildcard"
|
||||||
cname.example.org. IN CNAME www.example.net.
|
cname.example.org. IN CNAME www.example.net.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue