Using Varnish

Varnish Cache is a caching reverse proxy which is installed in front of all Acquia Cloud load balancing servers. Varnish increases application performance by caching anonymous user connections and serving them from memory instead of making requests to the Apache web server. Serving pages from memory is much faster than serving them from the Drupal/Apache/MySQL/PHP stack and also frees up resources on the server and database to handle the dynamic requests that can't be handled by Varnish. If Varnish can't fulfill a page request, it passes it through to the Drupal/Apache/MySQL/PHP stack. If the response from Apache is cacheable, Varnish stores it for faster responses to future requests.

For more information about using Varnish, see Introduction to Varnish.

What Varnish caches

Varnish caches responses to anonymous user requests. It also caches static assets, such as images, JavaScript, and CSS, both for anonymous and authenticated user requests (so long as they are not in the Drupal private file system). Note that on Acquia Cloud Varnish does not cache objects larger than 10 MB. You should use a CDN or other external storage system for serving large assets.

On Acquia Cloud, Varnish is configured with Grace mode, which enables serving items from the cache in cases where the web server is not responding. For more information, see Varnish Grace mode and Saint mode.

To see how Varnish caching is working with your application, you can examine the Varnish caching headers sent with each page and item request. For more information, see Varnish headers.

Configuring Varnish

You cannot configure Varnish yourself. Acquia has configured the shared Varnish installation in a way we believe is optimal for most applications. If you are an Acquia Cloud Enterprise customer, and you have dedicated load balancers, custom Varnish configurations may be available through an Acquia Professional Services engagement. See Custom Varnish configuration for Acquia Cloud Enterprise applications and contact your Acquia account manager for more information.

There is no need to install the Varnish Drupal module. It will not work with Acquia Cloud applications because it requires connections to the load balancers, which Acquia does not provide.

Configuring Drupal cache settings for Varnish

To take advantage of Varnish, you need to configure your Drupal application. To set your website cache options to external caching, open your Drupal application's Performance page. The cache settings depend on which version of Drupal you are using.

Drupal 8 cache settings

On the Performance page at /admin/config/development/performance, set the Page cache maximum age. This is the maximum time a page can stay in the Varnish cache. If you set this to <no caching>, the max-age header Drupal sends to Varnish is 0, which means it will not be cached. A reasonable setting is 6-12 hours.

Drupal 8 cache settings

Drupal 7 cache settings

On the Performance page at Configuration > Performance:

Drupal 7 cache settings

  1. Select Cache pages for anonymous users.
  2. Set the Minimum cache lifetime. The minimum cache lifetime prevents Drupal from clearing page and block caches after changes are made to nodes or blocks for a set period of time. This can cause unexpected behavior when editing content or when an external cache such as Varnish is employed. Therefore, minimum cache lifetime should be used with caution. If you are unsure, leave the minimum cache lifetime set to 0.
  3. Set the Expiration of cached pages. This is the maximum time a page can stay in the Varnish cache. If you set this to <none>, the max-age header Drupal sends to Varnish is 0, which means it will not be cached. A reasonable setting is 6-12 hours.

Bypassing the Varnish cache

Sometimes you may have a few pages with random or dynamic content that you want not to cache. You can selectively exclude certain paths from being cached so that dynamic content is actually dynamic. For information about how to do this, see Bypassing the Varnish cache.

Clearing the Varnish cache

You can clear (flush or purge) the Varnish cache using the Acquia Cloud interface:

  1. Sign in to the Acquia Cloud interface and select your application and environment.
  2. On the Overview page for the environment, click Clear Varnish.
  3. In the Clear caches dialog, select the domains for which you want to clear the Varnish caches. You can click All to clear the Varnish caches for all domains in this environment. Then click Clear to confirm.

You can also purge individual pages using the Acquia Purge module user interface, or with command-line commands. For more information, see Purging Varnish Cache on Acquia Cloud.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
By submitting this form, you accept the Mollom privacy policy.

Contact supportStill need assistance? Contact Acquia Support