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
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.
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 7 cache settings
On the Performance page at Configuration > Performance:
- Select Cache pages for anonymous users.
- 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.
- 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-ageheader 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:
- Sign in to the Acquia Cloud interface and select your application and environment.
- On the Overview page for the environment, click Clear Varnish.
- 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.