Skip to content

Instantly share code, notes, and snippets.

@bltb
Forked from perbu/grave-v4.vcl
Created October 4, 2016 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bltb/d73949f9aeecf2288d14181e82c998d2 to your computer and use it in GitHub Desktop.
Save bltb/d73949f9aeecf2288d14181e82c998d2 to your computer and use it in GitHub Desktop.
sub vcl_hit {
if (obj.ttl >= 0s) {
# normal hit
return (deliver);
}
# We have no fresh fish. Lets look at the stale ones.
if (std.healthy(req.backend_hint)) {
# Backend is healthy. Limit age to 10s.
if (obj.ttl + 10s > 0s) {
set req.http.grace = "normal(limited)";
return (deliver);
} else {
# No candidate for grace. Fetch a fresh object.
return(fetch);
}
} else {
# backend is sick - use full grace
if (obj.ttl + obj.grace > 0s) {
set req.http.grace = "full";
return (deliver);
} else {
# no graced object.
return (fetch);
}
}
}
sub vcl_backend_response {
set beresp.ttl = 10s;
set beresp.grace = 1h;
}
sub vcl_recv {
# intial state
set req.http.grace = "none";
}
sub vcl_deliver {
# copy to resp so we can tell from the outside.
set resp.http.grace = req.http.grace;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment