Add a serve_stale option for plugin/cache (#3468)
Automatically submitted.
This commit is contained in:
parent
24176a97e6
commit
b4df2d0d4c
6 changed files with 166 additions and 15 deletions
19
plugin/cache/setup.go
vendored
19
plugin/cache/setup.go
vendored
|
@ -1,6 +1,7 @@
|
|||
package cache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
@ -31,7 +32,7 @@ func setup(c *caddy.Controller) error {
|
|||
c.OnStartup(func() error {
|
||||
metrics.MustRegister(c,
|
||||
cacheSize, cacheHits, cacheMisses,
|
||||
cachePrefetches, cacheDrops)
|
||||
cachePrefetches, cacheDrops, servedStale)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -176,6 +177,22 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
|
|||
ca.percentage = num
|
||||
}
|
||||
|
||||
case "serve_stale":
|
||||
args := c.RemainingArgs()
|
||||
if len(args) > 1 {
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
ca.staleUpTo = 1 * time.Hour
|
||||
if len(args) == 1 {
|
||||
d, err := time.ParseDuration(args[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if d < 0 {
|
||||
return nil, errors.New("invalid negative duration for serve_stale")
|
||||
}
|
||||
ca.staleUpTo = d
|
||||
}
|
||||
default:
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue