middleware/cache: rename categories (#321)

Rename: positive -> success
negative -> denial

There is a third (unused category) which is error. Start using these
new in the caching middleware and later in the logging middleware.
This commit is contained in:
Miek Gieben 2016-10-08 15:12:28 +01:00 committed by GitHub
parent 6cf14746ad
commit b44d82839f
5 changed files with 21 additions and 16 deletions

View file

@ -9,7 +9,7 @@ cache [ttl] [zones...]
~~~ ~~~
* `ttl` max TTL in seconds. If not specified, the maximum TTL will be used which is 1 hour for * `ttl` max TTL in seconds. If not specified, the maximum TTL will be used which is 1 hour for
positive responses and half an hour for negative ones. noerror responses and half an hour for denial of existence ones.
* `zones` zones it should cache for. If empty, the zones from the configuration block are used. * `zones` zones it should cache for. If empty, the zones from the configuration block are used.
Each element in the cache is cached according to its TTL (with `ttl` as the max). Each element in the cache is cached according to its TTL (with `ttl` as the max).
@ -20,17 +20,19 @@ Or if you want more control:
~~~ txt ~~~ txt
cache [ttl] [zones...] { cache [ttl] [zones...] {
postive capacity [ttl] noerror capacity [ttl]
negative capacity [ttl] denial capacity [ttl]
} }
~~~ ~~~
* `ttl` and `zones` as above. * `ttl` and `zones` as above.
* `positive`, override the settings for caching positive responses, capacity indicates the maximum * `success`, override the settings for caching noerror 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.
* `negative`, override the settings for caching negative 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.
There is a third category (`error`) but those responses are never cached.
The minimum TTL allowed on resource records is 5 seconds. The minimum TTL allowed on resource records is 5 seconds.
If monitoring is enabled (via the `prometheus` directive) then the following extra metrics are added: If monitoring is enabled (via the `prometheus` directive) then the following extra metrics are added:

View file

@ -15,7 +15,7 @@ import (
) )
// Cache is middleware that looks up responses in a cache and caches replies. // Cache is middleware that looks up responses in a cache and caches replies.
// It has a positive and a negative cache. // It has a success and a denial of existence cache.
type Cache struct { type Cache struct {
Next middleware.Handler Next middleware.Handler
Zones []string Zones []string

View file

@ -58,7 +58,7 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
for c.NextBlock() { for c.NextBlock() {
switch c.Val() { switch c.Val() {
// first number is cap, second is an new ttl // first number is cap, second is an new ttl
case "positive": case "success":
args := c.RemainingArgs() args := c.RemainingArgs()
if len(args) == 0 { if len(args) == 0 {
return nil, c.ArgErr() return nil, c.ArgErr()
@ -75,7 +75,7 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
} }
ca.pttl = time.Duration(pttl) * time.Second ca.pttl = time.Duration(pttl) * time.Second
} }
case "negative": case "denial":
args := c.RemainingArgs() args := c.RemainingArgs()
if len(args) == 0 { if len(args) == 0 {
return nil, c.ArgErr() return nil, c.ArgErr()

View file

@ -19,22 +19,26 @@ func TestSetup(t *testing.T) {
{`cache`, false, defaultCap, defaultCap, maxNTTL, maxTTL}, {`cache`, false, defaultCap, defaultCap, maxNTTL, maxTTL},
{`cache {}`, false, defaultCap, defaultCap, maxNTTL, maxTTL}, {`cache {}`, false, defaultCap, defaultCap, maxNTTL, maxTTL},
{`cache example.nl { {`cache example.nl {
positive 10 success 10
}`, false, defaultCap, 10, maxNTTL, maxTTL}, }`, false, defaultCap, 10, maxNTTL, maxTTL},
{`cache example.nl { {`cache example.nl {
positive 10 success 10
negative 10 15 denial 10 15
}`, false, 10, 10, 15 * time.Second, maxTTL}, }`, false, 10, 10, 15 * time.Second, maxTTL},
{`cache 25 example.nl { {`cache 25 example.nl {
positive 10 success 10
negative 10 15 denial 10 15
}`, false, 10, 10, 15 * time.Second, 25 * time.Second}, }`, false, 10, 10, 15 * time.Second, 25 * time.Second},
{`cache aaa example.nl`, false, defaultCap, defaultCap, maxNTTL, maxTTL}, {`cache aaa example.nl`, false, defaultCap, defaultCap, maxNTTL, maxTTL},
// fails // fails
{`cache example.nl { {`cache example.nl {
positive success
negative 10 15 denial 10 15
}`, true, defaultCap, defaultCap, maxTTL, maxTTL},
{`cache example.nl {
success 15
denial aaa
}`, true, defaultCap, defaultCap, maxTTL, maxTTL}, }`, true, defaultCap, defaultCap, maxTTL, maxTTL},
{`cache example.nl { {`cache example.nl {
positive 15 positive 15

View file

@ -24,7 +24,6 @@ TSIG key information, something like `transfer out [address...] key [name] [base
~~~ ~~~
file dbfile [zones... ] { file dbfile [zones... ] {
transfer from [address...]
transfer to [address...] transfer to [address...]
no_reload no_reload
} }