Purging Varnish cache on Acquia Cloud

Varnish

There are major advantages to having long cache lifetimes and expires, which means that it's important to use Varnish with Drupal for performance improvements. However, when changes are made or new content is published, you don't want to wait a long time for visitors (including non-authenticated users) to see the changes. In these cases, you should periodically purge your Varnish cache.

Varnish excels at storing pages, CSS, and JavaScript files, as well as multimedia files, for as long as possible, so that visitor requests don't hit the back-end (in most scenarios, this will be Apache). This greatly helps with performance and allows a website to scale much better than it would if only Apache was serving pages. When your organization decides to implement a caching strategy, you will need to explore all available options and decide what's best for your situation. For more information, see the Using Varnish documentation page.

Select from the following methods to purge your Varnish cache:

Using Acquia Purge

If you're an Acquia Cloud-hosted site, the Acquia Purge module is your fastest and most convenient way to purge caches. It provides a non-programmatic way to purge Varnish-powered balancers through a UI, and it integrates the Rules and Cache Expiration modules for extra flexibility and proactive purging.

Read more about installing and using Acquia Purge in the Acquia Purge documentation.

Purging Programmatically

While Acquia Purge is Acquia's best recommendation when it comes to implementing a caching strategy, another good method is to use the Purge and Cache Expiration modules.

The Purge module clears URLs from reverse proxy caches like Varnish and also issues an http PURGE request to them. It works with the Cache Expiration module to act on events that are likely to expire URLs from the proxy cache and interact with Rules and Drush. This results in delivering faster content updates to end users. Acquia Purge is recommended on Acquia Cloud because it has many of the same features, and the maintainers for Purge and Acquia Purge work closely to ensure compatibility.

If you absolutely must purge a page manually from Acquia Cloud, you can learn how to manually purge a page.

Leveraging Acquia Cloud API

Acquia has developed the Acquia Cloud API for developers to be able to take advantage of even more automation as part of their daily workflow. Acquia Cloud API is a RESTful web interface that allows developers to extend, enhance, and customize Acquia Cloud. It includes developer workflow, site management, and provisioning capabilities. Of all its commands, the relevant one here is the delete the domain cache instance method:

DELETE /sites/:site/envs/:env/domains/:domain/cache

The preceding command triggers a Varnish cache purge for a specific domain. It works exactly like the Workflow UI Varnish cache invalidation discussed in Purging a domain on Acquia Cloud, but in the context of the automated Cloud API. Here's an example:

curl -s -u user:pass -X DELETE \ 
 https://site.com/v1/sites/site/envs/prod/domains/site.com/cache.json

For more information about the Acquia Cloud API, see the Acquia Cloud API documentation page, and check out the Cloud API reference page.

Leveraging Acquia Cloud Hooks

Cloud Hooks allow you to automate almost anything as part of your Workflow actions. A Cloud Hook is a script in your code repository that Acquia Cloud executes on your behalf when a triggering action occurs (for example, a database, some code or some files copy from one environment to the other). You can definitely implement Cloud API Varnish cache clears as part of Cloud Hooks triggers, for instance when you are deploying code from Dev to Stage.

For more information about Acquia Cloud Hooks, read our Acquia Cloud Hooks documentation page, and check out the Cloud Hooks GitHub repository.

Using other purge methods

Although Acquia Purge is the preferred and safest method of cache purging, there are some other methods that you can use if necessary:

Contact supportStill need assistance? Contact Acquia Support