Varnish caching offers protection for your application, and continues to provide content for your users, sometimes even if your application is down for a short period. However, sometimes you must remove content faster than the standard Varnish timeout for your application. Two methods you can use to clear your Varnish cache are Acquia Purge (recommended) and command-line instructions.
Acquia Purge (recommended)
The Acquia Purge module is the easiest way to clear specific pages or groups of pages from Varnish cache. See Installing Acquia Purge for installing and configuring this module.
Command line
If you must use the command line to manually purge the Varnish cache for a specific page, the easiest and most straightforward way is to manually purge the page using cURL with the regular -X PURGE
request method to interact with the HTTP infrastructure. Next, pass it to Acquia’s custom X-Acquia-Purge
header with the Unix site name from which to purge the specified page.
Connect to one of your Acquia web infrastructure using SSH and run one of the following commands. Replace [sitename]
with your Unix site name and the path with the page you want to clear from the Varnish cache. You will want to purge both a given path and its related RSS feed, if there is any (rss.xml
by default). You must run this command for each page you want to purge from the Varnish cache, since you can’t pass the command a list of pages to purge all at once.
- Manually clearing caches for applications not using ELBs
- Manually clearing caches for applications using ELBs
- Manually clearing caches for applications using CDNs
- Considerations when clearing caches manually
Manually clearing caches for applications not using ELBs
If you aren’t using an elastic load balancer (ELB), you must manually clear a page from Varnish caches with the following command:
# Replace 'sitename' below with the appropriate value.
curl -X PURGE -H "X-Acquia-Purge:sitename" -H "Accept-Encoding: gzip" http://example.com/path/to/page
Manually clearing caches for applications using ELBs
If your application uses an ELB, you must send requests to each active balancer, using the desired domain as a Host
header.
If you want to purge a page on example.com
, and the domain is hosted by bal-1234
and bal-1235
in the devcloud
realm, you would use the following commands:
curl -X PURGE -H "X-Acquia-Purge:[sitename]" --compress -H "Host: example.com" http://bal-1234.devcloud.hosting.acquia.com/foo/bar
curl -X PURGE -H "X-Acquia-Purge:[sitename]" --compress -H "Host: example.com" http://bal-1235.devcloud.hosting.acquia.com/foo/bar``
To use these commands, replace bal-1234.devcloud.hosting.acquia.com
with the appropriate infrastructure and realm. You can find the full list on the environment’s Infrastructure page.
If your application uses SSL and has a HTTP to HTTPS redirect in place, you must modify the above command and send the request to each balancer as follows:
curl -k -X PURGE -H "X-Acquia-Purge:[sitename]" --compress -H "Host: www.example.com" https://bal-12345.prod.hosting.acquia.com/foo/bar
Manually clearing caches for applications using CDNs
If your application is behind a content delivery network (CDN), such as Edge or Akamai, you must first send a request to the active load balancer or the balancer’s Elastic IP Address (EIP) by using a command like to the following:
curl -X PURGE -H "X-Acquia-Purge:[sitename]" -H "Accept-Encoding: gzip" -H "Host: example.com" http://[eip_address]
Your [eip_address]
is located on your Cloud Platform Infrastructure page.
While this command clears the Varnish caches at the balancer layer, you must also clear the cache for this path in your CDN for the updated content to display to your application’s users. Edge subscriptions using the published caching recommendations will display the updated content within 59 seconds.
Manually clearing caches for applications using SSL
If your website redirects all traffic from HTTP to HTTPS, you must ignore the balancer’s SSL state, and explicitly specify the HTTPS protocol, as follows:
curl -k -X PURGE -H "X-Acquia-Purge:[sitename]" --compress -H "Host: www.example.com" https://bal-12345.prod.hosting.acquia.com/
Considerations when clearing caches manually
Varnish stores caches per domain, so if you configure several domains to reference the same application (for example, www.mysite.com
and cms.mysite.com
), you must make individual curl
requests for each domain referencing the page you want to clear from Varnish cache.
Running the purge commands on this page won’t invalidate Drupal’s caches. If Drupal cache objects aren’t yet scheduled for purging from the cache and Memcache, purging the Varnish cache won’t make any difference. As a result, you must think of a way to clear the relevant cache id (CID) for the cache objects you must purge first.
For more information about clearing Drupal’s caches, see Clearing or rebuilding Drupal’s cache. Acquia recommends that you leverage Drupal’s cache-clearing features in a Rule or a custom module to clear the cache items that are going to be triggered by the Varnish cache purge.
For more information about the different layers of caching, see Caching overview.