Purging Varnish

Varnish as a rule will maintain its own cache contents, updating the entries as necessary. As with any cache, it isn't recommended to manually clear the cache - as it will reduce its effectiveness.

However, if you need to instantly clear the cache, it can be performed very easily on a per-domain basis, and per load balancer basis and per URI basis.

Purging

Single Domain

Purging the Varnish cache can be completed by passing the PURGE command to any URL of your choice, Perl regular expressions (regex) can also be used.

curl –X PURGE http://www.example.com/
curl –X PURGE http://www.example.com/mycategory/.*
curl –X PURGE http://www.example.com/myproduct.html

All domains

curl -X PURGE lb1.i
curl -X PURGE lb1.i/.*
curl -X PURGE lb1.i/myproduct.html

Replace lb1.i with your load balancer node as necessary.

Sample PHP script

Save the following file in any location on your MageStack stack, then visit it in your web browser. If you are using additional loadbalancers (ie. MageStack Edge), you can add the additional hosts to the array of $mseNodes at the top of the file.