Skip to content

Android Tutorial Station

Purge cache in Varnish and WordPress

One of the tasks that I have had to face after installing Varnish Cache on a server is to purge the cache correctly when I use WordPress. Purging cache in Varnish and WordPress automatically is something that can be achieved through the installation of a plugin and then we will see two plugins that in my opinion are the best alternatives to purge the Varnish cache.

How to purge cache in Varnish with WordPress

The first thing will be to have our VCL file of Vanrnish correctly configured. An example of a configuration file that allows purging with the plugins discussed in this article is:

 #IP/Hosts a los que se permite la peticion de purga acl purge { 	"localhost"; 	""; }  # Aceptar PURGE de W3 Total Cache y Varnish HTTP Purge sub vcl_hit {     if (req.request == "PURGE") {         purge;         error 200 "Purged.";     } }  sub vcl_miss {     if (req.request == "PURGE") {         purge;         error 200 "Purged.";     } }  # Configuraciones recv sub vcl_recv {  	#+++++ Purgado 	if (req.request == "PURGE") { 		if (!client.ip ~ purge) { 			error 405 "Not allowed."; 		} 		ban("req.url ~ ^" + req.url + "$ && == " +; 	}  #resto de configuraciones ... 

Purge Varnish cache with W3 Total Cache

This is a classic among cache plugins, it is one of the most complete and full of features. W3 Total Cache offers us the possibility to purge the Varnish cache , we just have to configure the IP from which purge requests are allowed, which is generally IP as seen in the following image.

Personally when I use Varnish I deactivate all the functionality of W3 Total Cache , using only this plugin to purge the cache. Recall that the plugin allows us to configure the purge policies, to decide which elements to purge when the articles are created, edited or new comments are published.

Already the plugin itself advises us to keep the default configuration so that purge requests do not affect the performance of the server.

Varnish HTTP Purge

The Varnish HTTP Purge plugin is simple but fulfills its purpose. It is a plugin that you have to install and then edit the wp-config.php file of our WordPress to add the line:

With this line we specify the IP from where purge requests are made. By default, most Varnish installations will work with IP , but if our VCL configuration file specifies another IP, that line must be modified.

Like W3 Total Cache, it will clear the Varnish cache when an article is published or edited or new comments are published, but it does not allow us any configuration when choosing which items to purge.

So … what WordPress plugin used to purge Varnish cache?

Well, the answer is very simple, if you want to have more control over the purge policies, then W3 Total Cache is a better option while if you are looking for something simple to install and configure, Varnish HTTP Purge is your best option .

I currently use Varnish HTTP Purge, because it is simpler and less intrusive in my WordPress blogs, but if you want more control and W3 Total Cache configuration options it will better fit your needs.

No comments yet.

Leave a Reply

Your email address will not be published.

Comments (0)