The following instructions assume you have the latest version of the Varnish HTTP Purge plugin. If your WP Admin shows that an update is available for this plugin, please update the plugin if you are having trouble with these steps.
Caching on DreamPress is done via a Varnish server. The Varnish HTTP Purge plugin is installed on all new and upgraded DreamPress installations. This plugin automatically flushes the cache when pages or posts are published.
If you have copied over an existing WordPress site from another host to DreamPress, installing this plugin is highly recommended so that managing your DreamPress cache is automated and does not require your attention under normal circumstances.
When would you need to purge your cache?
You should purge your cache when you make changes to your site such as when you customize or create new content. The new changes may not show, since the old version of your site may be cached. Purging your cache can help to push your changes live so visitors see the most recent version of your site.
Manually purging the Varnish cache via the plugin
The Varnish HTTP Purge plugin (included in all DreamPress installs) comes with an Empty Cache button. This button can be found in the main dashboard of WordPress, and clicking it will purge the entire cache. USE THIS SPARINGLY. The whole point of caching is to cache.
A better alternative is to selectively purge the cache of a specific item that you changed, if the changes aren’t showing up. You can now purge a post or page from cache using the plugin’s Empty Cache button.
- Make sure you are logged into your WP Admin.
- Load the URL of the page or post you want to purge from cache.
- In the WP Admin toolbar at the top of the page, hover over the “Cache” button in the Admin toolbar and select “This Page’s Cache.”
- The page reloads and the page is purged from cache.
If you need to selectively purge specific files such as CSS you manually changed and uploaded via SFTP/SSH, you'll still need to do it via SSH for now.
Temporarily bypassing the Varnish cache
The Varnish HTTP Purge plugin has a “Development Mode” feature which allows you to temporarily bypass all caching of HTTP requests. This prevents visitors from seeing any cached content on your WordPress site. You might find this useful if your site is still under development or if you are making major changes to the design. In addition, if you are having issues with a theme or plugin, the developer might ask you to try disabling cache to test it further.
You can enable this feature for 24 hours, after which it will automatically disable itself. You can also manually turn off Development Mode before the 24 hours are over, when you are done with your changes or testing. This allows your site to be cached by Varnish again and improves page loading times for your visitors. Development Mode makes your site run slower, so please use with caution.
To disable Varnish caching (activate Development Mode):
- Open the WordPress Admin dashboard (e.g., 'example.com/wp-admin').
- Navigate to ‘Varnish' > 'Settings’.
- The Varnish HTTP Purge Settings page opens:
- Scroll down to the 'Development Mode Settings' section.
- Check the 'Activate Development Mode' checkbox, and then click the blue Save Settings button.
- The following confirmation message appears on the settings page:
Varnish HTTP Purge Development Mode remains active for 24 hours, after which it disables and caching resumes normally. You can also manually disable Development Mode on this same page by un-checking the 'Development Mode' box and then clicking the 'Save Settings' button.
Manually purging the Varnish cache via SSH
A Purge is an HTTP request using the method
PURGE. In DreamPress, the request URI can be interpreted in several different ways, one of which is as a Perl Compatible Regular Expression (PCRE). If the URL includes characters that look like a PCRE (for example
.*), then it will be treated as a PCRE, so be sure to always include
.* if your intention is to purge multiple pages. See the DreamHost Varnish config for more details.
The DreamPress Varnish config uses IP-based Access Control Lists (ACLs) so that the purge request must come from the DreamPress machine. Purge requests from other IPs will show
error 405 Not allowed.
The following is an example command of how to purge a single CSS file:
[server]$ curl -X PURGE "http://example.com/wp-content/themes/mytheme/style\.css"
If your site is using www or any other subdomain, you must use the complete domain name in the purge URL. Make sure the domain part matches exactly with what appears when visiting your site.
Note that . (dot) and other PCRE metacharacters need to be escaped if they are present in the path. Do not escape
. (dot) characters in the domain name.
If you are making changes to your theme files, or updating themes, an easy way to clear all theme files from your cache would be:
[server]$ curl -X PURGE "http://example.com/wp-content/themes/.*"
You can also target specific types of files using the following syntax:
[server]$ curl -X PURGE "http://example.com/wp-content/themes/.*\.js" [server]$ curl -X PURGE "http://example.com/wp-content/themes/.*\.css"
If the Varnish HTTP Purge plugin is active, you can run the following command to purge the Varnish cache:
[server]$ wp varnish purge
Purging cache manually via SSH with Cloudflare
If you’re using DreamPress behind a proxy like Cloudflare or another firewall service, you need to run a different command.
[server]$ curl -X PURGE "http://188.8.131.52/wp-content/themes/mytheme/style*" -H "host:www.example.com"
To find your Varnish IP, go to (Panel > 'Domains' > 'Manage Domains') and click on the DNS link beneath the domain. The IP address entry for the www or blank A record is your varnish server. For example:
www A 184.108.40.206
If you’ve configured DreamPress properly for Varnish, you can use the wp-cli command:
[server]$ wp varnish purge