Information for: DEVELOPERS   PARTNERS

Manually purging a page from Varnish cache

Important

Acquia strongly recommends using the preferred method of Varnish® cache purging, Acquia Purge. For more details, see Purging Varnish cache on Cloud Platform.

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.

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 server. 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 servers 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.

Note

  • The following commands won’t work with the acquia-sites.com default domains provisioned with Cloud Platform environments.
  • Site Factory subscribers must use the command to ignore the balancer’s SSL state.

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 server and realm. You can find the full list on the environment’s Servers page.

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 Servers 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/

For Site Factory subscribers

Site Factory subscribers must use this version of the command, replacing prod with the appropriate realm. If you need help determining the correct realm for your subscription, contact Acquia Support.

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 on Drupal.org. Acquia recommends 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.

Important

Acquia strongly recommends against clearing all Drupal caches, because complete cache clears will negatively affect your application’s performance while caches are rebuilt.

For more information about the different layers of caching, see the Caching overview page.