Skip to content

Instantly share code, notes, and snippets.

@rezan
Last active July 21, 2017 13:55
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 rezan/91499d1588b4148612e99fda4f3f9ea8 to your computer and use it in GitHub Desktop.
Save rezan/91499d1588b4148612e99fda4f3f9ea8 to your computer and use it in GitHub Desktop.
Properly handle grace across multiple tiers
vcl 4.0;
# Include this VCL on all tiers
# Call this once on the Edge tier
sub dvcl_init_edge
{
unset req.http.X-DVCL-skip-grace;
}
sub vcl_recv
{
unset req.http.X-DVCL-graced;
}
sub vcl_hit
{
if (obj.ttl < 0s) {
set req.http.X-DVCL-graced = "true";
if (req.http.X-DVCL-skip-grace == "true") {
return (fetch);
}
}
# Fall thru to vcl_hit and possibly hit conditional grace/miss logic
}
sub vcl_backend_fetch
{
# If we come here, we are either a bgfetch or a condition grace/miss
# In either case, we want something fresh, so disable grace on all following tiers
if (bereq.http.X-DVCL-graced == "true") {
set bereq.http.X-DVCL-skip-grace = "true";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment