Varnish is a caching server that sits in front of your web server and keeps its own copy of your pages. When your content changes, Varnish has to be told to drop that copy. The Varnish integration sends purge requests to your Varnish server when Powered Cache clears the whole cache, so visitors do not keep seeing old pages.
Available in: Powered Cache Premium
Where to find it: Powered Cache → Integrations
Requires: a Varnish server in front of your site that accepts PURGE requests from your WordPress server, and pretty permalinks (any setting other than Plain in Settings → Permalinks).
How Varnish purging works #
Powered Cache sends an HTTP request with the method PURGE to your Varnish server. The request carries your site’s domain in the Host header and an X-Purge-Method header:
X-Purge-Method: regexwith the path/.*: purge everything on the site. Powered Cache uses this for every automatic purge.X-Purge-Method: default: purge one exact URL. Only the WP-CLI command sends this kind of request.
The request goes to http:// plus the address in Varnish IP Addresses, even when your site uses HTTPS. Your Varnish configuration (VCL) must allow PURGE requests from the IP address of your WordPress server, and treat X-Purge-Method: regex as a pattern match on the URL. If your host set up Varnish for you, ask them whether it accepts purge requests in this format.
When Varnish is purged #
Powered Cache purges the whole Varnish cache for your site when:
- You run Purge All Cache from the admin bar or from Powered Cache → Tools.
- You switch themes or save changes in the Customizer.
- A WordPress import starts or ends.
- The Autoptimize plugin clears its cache.
In Powered Cache Premium 4.1, publishing, updating or deleting a single post does not send a purge request to Varnish, and neither does wp powered-cache purge. Keep the cache lifetime in Varnish short, or run Purge All Cache after changes that must be visible right away.
Set up Varnish purging #
- Make sure your Varnish server accepts
PURGErequests from your WordPress server, as described above. - Go to Powered Cache → Integrations.
- Turn on Varnish (Purge Varnish cache).
- Enter the address of your Varnish server in Varnish IP Addresses.
- Click Save Settings.
- Change something visible on a page, run Purge All Cache, and reload the page in a private browser window to confirm the change appears.
Settings #
Varnish #
Turns Varnish purging on. Default: off. Turn it on only if a Varnish server actually caches your site. Otherwise the purge requests have no effect.
Varnish IP Addresses #
Where Powered Cache sends the purge requests. Default: empty.
- Enter one address on a single line: an IP address such as
127.0.0.1, or an IP address with a port such as127.0.0.1:6081when Varnish does not listen on port 80. - Do not enter
http://or a path. Powered Cache adds them. - Leave the field empty if Varnish answers on your site’s own domain name. Requests then go to that domain. The Settings check shows a note in this case, unless the address is set in
wp-config.php.
Multiple Varnish servers: although the field accepts several lines, Powered Cache Premium 4.1 uses its whole content as a single address. A second line makes the address invalid, and no server is purged. If you run several Varnish servers, enter one address that forwards purge requests to all of them, such as a load balancer, or ask a developer to use the hooks listed below.
Set the address in wp-config.php #
You can also set the address with the VHP_VARNISH_IP constant, the same constant the Varnish HTTP Purge plugin uses. It takes priority over the Varnish IP Addresses field.
define( 'VHP_VARNISH_IP', '127.0.0.1:6081' );
Caveats #
- Plain permalinks: while Settings → Permalinks is set to Plain, administrators see a notice asking for custom permalinks, and only Purge All Cache purges Varnish. Theme, Customizer and import events are ignored.
- Varnish and page caching together: Powered Cache page caching and Varnish can run side by side. After a Purge All Cache, both caches are empty and fill up again with the next visits, or with Cache Preload.
Troubleshooting #
Varnish still serves old pages after Purge All Cache #
- Check that Varnish IP Addresses contains exactly one address and no
http://. - Check your Varnish log for incoming
PURGErequests. If they arrive but are refused, allow your WordPress server’s IP address in the VCL. - If Varnish listens on a port other than 80, add the port to the address.
- Test a purge from the command line with WP-CLI.
For developers #
The powered_cache_varnish_ip filter changes the purge target, powered_cache_varnish_http_purge_schema changes http://, powered_cache_varnish_home_url changes the home URL used for full purges, and the powered_cache_varnish_after_purge_url action runs after each purge request. powered_cache_varnish_http_purge_events and powered_cache_varnish_http_purge_events_full control which WordPress actions trigger a purge. See the Hooks Reference.
Related docs #
- Clear Cache
- WP-CLI Commands (Premium)
- Sucuri Integration (Premium)
- Hosting Compatibility