Add MINTTL parameter to cache configuration. (#2055)

* Add success min TTL parameter to cache.

* Add MINTTL to README.

* Update README.

* Add MINTTL to negative cache.

* Remove unnecessary variable name.

* Address review comments.

* Configure cache in TestCacheZeroTTL to have 0 min ttl.
This commit is contained in:
Aaron Riekenberg 2018-09-03 14:26:02 -05:00 committed by Tobias Schmidt
parent 4c6c9d4b27
commit b42eae7a04
5 changed files with 111 additions and 31 deletions

22
plugin/cache/setup.go vendored
View file

@ -101,6 +101,17 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
return nil, fmt.Errorf("cache TTL can not be zero or negative: %d", pttl)
}
ca.pttl = time.Duration(pttl) * time.Second
if len(args) > 2 {
minpttl, err := strconv.Atoi(args[2])
if err != nil {
return nil, err
}
// Reserve < 0
if minpttl < 0 {
return nil, fmt.Errorf("cache min TTL can not be negative: %d", minpttl)
}
ca.minpttl = time.Duration(minpttl) * time.Second
}
}
case Denial:
args := c.RemainingArgs()
@ -122,6 +133,17 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
return nil, fmt.Errorf("cache TTL can not be zero or negative: %d", nttl)
}
ca.nttl = time.Duration(nttl) * time.Second
if len(args) > 2 {
minnttl, err := strconv.Atoi(args[2])
if err != nil {
return nil, err
}
// Reserve < 0
if minnttl < 0 {
return nil, fmt.Errorf("cache min TTL can not be negative: %d", minnttl)
}
ca.minnttl = time.Duration(minnttl) * time.Second
}
}
case "prefetch":
args := c.RemainingArgs()