plugin/cache: Add refresh mode setting to serve_stale (#5131)
This PR adds an optional REFRESH_MODE parameter on the serve_stale configuration directive of the cache plugin, which verifies that the upstream is still unavailable before returning stale entries. Signed-off-by: Antoine Tollenaere <atollena@gmail.com>
This commit is contained in:
parent
c3572fdb30
commit
66f2ac7568
6 changed files with 170 additions and 25 deletions
12
plugin/cache/setup.go
vendored
12
plugin/cache/setup.go
vendored
|
@ -166,11 +166,11 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
|
|||
|
||||
case "serve_stale":
|
||||
args := c.RemainingArgs()
|
||||
if len(args) > 1 {
|
||||
if len(args) > 2 {
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
ca.staleUpTo = 1 * time.Hour
|
||||
if len(args) == 1 {
|
||||
if len(args) > 0 {
|
||||
d, err := time.ParseDuration(args[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -180,6 +180,14 @@ func cacheParse(c *caddy.Controller) (*Cache, error) {
|
|||
}
|
||||
ca.staleUpTo = d
|
||||
}
|
||||
ca.verifyStale = false
|
||||
if len(args) > 1 {
|
||||
mode := strings.ToLower(args[1])
|
||||
if mode != "immediate" && mode != "verify" {
|
||||
return nil, fmt.Errorf("invalid value for serve_stale refresh mode: %s", mode)
|
||||
}
|
||||
ca.verifyStale = mode == "verify"
|
||||
}
|
||||
default:
|
||||
return nil, c.ArgErr()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue