Created
October 5, 2016 11:10
-
-
Save sjparkinson/e056a063e1c2b7ef1f8dc899ef66d094 to your computer and use it in GitHub Desktop.
Examples on how to purge the cache in Varnish.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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