aboutsummaryrefslogtreecommitdiff
path: root/middleware/cache/setup.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-11-09 10:01:26 +0000
committerGravatar GitHub <noreply@github.com> 2016-11-09 10:01:26 +0000
commit6abbe231e5a587940d7cc64de4348ced05b70828 (patch)
tree88839cfd70fb2ac9bd04718cf3d130b7630190fb /middleware/cache/setup.go
parentda742ed5968abc12417fbae1cfcadc09c0f53186 (diff)
downloadcoredns-6abbe231e5a587940d7cc64de4348ced05b70828.tar.gz
coredns-6abbe231e5a587940d7cc64de4348ced05b70828.tar.zst
coredns-6abbe231e5a587940d7cc64de4348ced05b70828.zip
middleware/cache: cache 0 will be capped at 5 (#408)
* middleware/cache: cache 0 will be capped at 5 cache 0 would return TTL=0 records, up that to the documented minimum of 5 seconds. * middleware/cache: check for 0 TTL Handle 0 TTL differently and return an error, we might need to special case this in the future.
Diffstat (limited to 'middleware/cache/setup.go')
-rw-r--r--middleware/cache/setup.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/middleware/cache/setup.go b/middleware/cache/setup.go
index 11a35ddc4..337930fe4 100644
--- a/middleware/cache/setup.go
+++ b/middleware/cache/setup.go
@@ -1,6 +1,7 @@
package cache
import (
+ "fmt"
"strconv"
"time"
@@ -49,6 +50,10 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
// first args may be just a number, then it is the ttl, if not it is a zone
ttl, err := strconv.Atoi(args[0])
if err == nil {
+ // Reserve 0 (and smaller for future things)
+ if ttl <= 0 {
+ return nil, fmt.Errorf("cache TTL can not be zero or negative: %d", ttl)
+ }
ca.pttl = time.Duration(ttl) * time.Second
ca.nttl = time.Duration(ttl) * time.Second
args = args[1:]
@@ -77,6 +82,10 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
if err != nil {
return nil, err
}
+ // Reserve 0 (and smaller for future things)
+ if pttl <= 0 {
+ return nil, fmt.Errorf("cache TTL can not be zero or negative: %d", pttl)
+ }
ca.pttl = time.Duration(pttl) * time.Second
}
case Denial:
@@ -94,6 +103,10 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
if err != nil {
return nil, err
}
+ // Reserve 0 (and smaller for future things)
+ if nttl <= 0 {
+ return nil, fmt.Errorf("cache TTL can not be zero or negative: %d", nttl)
+ }
ca.nttl = time.Duration(nttl) * time.Second
}
default: