Skip to content

Instantly share code, notes, and snippets.

@sjparkinson
Created October 5, 2016 11:10
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 sjparkinson/e056a063e1c2b7ef1f8dc899ef66d094 to your computer and use it in GitHub Desktop.
Save sjparkinson/e056a063e1c2b7ef1f8dc899ef66d094 to your computer and use it in GitHub Desktop.
Examples on how to purge the cache in Varnish.
vcl 4.0;
sub vcl_recv {
// Allow PURGE requests to remove a specific object if it exists.
if (req.method == "PURGE") {
return (purge);
}
// Allow BAN requests, adding a lurker friendly ban to the ban list.
if (req.method == "BAN") {
ban ("obj.http.X-Ban-Host == " + req.http.Host + " && obj.http.X-Ban-Url == " + req.url);
return (synth(200));
}
// Allow REFRESH requests to update cached objects.
if (req.method == "REFRESH") {
req.hash_always_miss = true;
}
}
sub vcl_backend_response {
// Attach ban related headers to the cache object.
set beresp.http.X-Ban-Host = bereq.http.Host;
set beresp.http.X-Ban-Url = bereq.url;
}
sub vcl_deliver {
// Remove debug and logic headers.
unset resp.http.X-Ban-Host;
unset resp.http.X-Ban-Url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment