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.

To purge the index page:

curl -IX PURGE https://www.example.com/

To purge all pages within a category using regex:

curl -IX PURGE https://www.example.com/mycategory/.*

To purge a single product page:

curl -IX PURGE https://www.example.com/myproduct.html

All domains

To purge the index page:

curl -IX PURGE lb1.i

To purge all pages using regex:

curl -IX PURGE lb1.i/.*

To purge a single product page:

curl -IX PURGE lb1.i/myproduct.html

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

Sample PHP script (For Magento 1 only)

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.