I'm looking for a way to clear the cache for all domains and all URLs in Varnish.
Currently, I would need to issue individual commands for each URLs, for example:
curl -X PURGE http://example.com/url1
curl -X PURGE http://example.com/url1
curl -X PURGE http://subdomain.example.com/
curl -X PURGE http://subdomain.example.com/url1
// etc.
While I'm looking for a way to do something like
curl -X PURGE http://example.com/*
And that would clear all URLs under example.com, but also all URLs in sub-domains of example.com, basically all the URLs managed by Varnish.
Any idea how to achieve this?
This is my current VCL file:
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# Command to clear the cache
# curl -X PURGE http://example.com
if (req.method == "PURGE") {
return (purge);
}
}
Use "systemctl start/restart/stop varnish".
According to Varnish documentation, “A purge is what happens when you pick out an object from the cache and discard it along with its variants.” A Varnish purge is very similar to a Magento cache clean command (or clicking Flush Magento Cache in the Admin).
Banning is a concept in Varnish that allows expression-based cache invalidation. This means that you can invalidate multiple objects from the cache without the need for individual purge calls. A ban is created by adding a ban expression to the ban list.
With Varnish 4.0 I ended up implementing it with the ban
command:
sub vcl_recv {
# ...
# Command to clear complete cache for all URLs and all sub-domains
# curl -X XCGFULLBAN http://example.com
if (req.method == "XCGFULLBAN") {
ban("req.http.host ~ .*");
return (synth(200, "Full cache cleared"));
}
# ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With