Ban is a bit different from Purge. Banned objects remain in memory, but banning is faster than purging(which you do one by one). It does not actually remove the object, just bans it from being used. Like sweeping it under the rug. Here is the official Varnish 3 Documentation https://www.varnish-cache.org/docs/3.0/tutorial/purging.html.
Purge may be more of use for your use-case; the examples I will give work, however they aren’t precisely the best way of doing it.
First the purge method used to be just called ‘purge’ in Varnish 2.x, but they renamed it to ‘ban’ in Varnish 3.0. Just to throw you off they made a new tool called ‘purge’ that is less sophisticated than ‘ban’ as it only purges exactly matched items. More or less one thing at a time.
If you want to use the new purge, you need to have some specific VCL setup see here:
In Varnish 2.x I would have used a cURL request:
curl -X PURGE www.mydomain.com
However in Varnish 3.x this purges only the home page default document itself from that domain.
In order to purge the whole domain we need to use ‘ban’.
A common use case for this is if you have a high Varnish TTL and just uploaded new content. Purging will give you that new content. However, it will not stop new content from being cached or being served. Just bans content already cached. Once the TTL expires on the banned cache, list is cleared.
Don’t purge an entire site during high traffic, this could cause high load on the server. (‘ban’ lets you purge selectively as well).
You can’t flush public or user caches, this doesn’t negate the need to increment filenames on any assets with long expiry time. (and / or managed public cache-control headers carefully).
There are several ways to get this done, the simplest way is to use varnishadm, which you can go into and contr5ol manually, or run on the command line by passing the required command to it.
Here is an example:
sudo varnishadm "ban req.http.host ~ www.mydomain.com"
You can also go more complicated and tell it to for instance ban all .css files:
sudo varnishadm "ban req.http.host ~ www.mydomain.com && req.url ~ .css"
Afterwords we can test it out: