Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.