This is a list of four Drupal 7 cache related modules that can work together to improve the performance and scalability of a Drupal website:
- Varnish HTTP Accelerator Integration
- Cache Expiration
- Memcache API and Integration
- APC – Alternative PHP Cache
Three of the four modules provide Drupal integration for Varnish, APC, and Memcache. Cache Expiration provides support for dynamic cache expiration when nodes and other entities are added or updated. This is useful because it allows the site administrator to raise the ‘cache_lifetime’ and ‘page_cache_maximum_age’ values increasing cache hit rates.
If a new node is added or a user comments on an existing one, the page will be dynamically purged and anonymous users who visit the page will see the new content, even if the lifetime of the cached page had not yet been reached.
As part of the process of setting up the cache modules it is necessary to make changes in the settings.php file as follows, adjust the module include path to suit the local environment:
// Reverse Proxy $conf['reverse_proxy'] = TRUE; $conf['reverse_proxy_addresses'] = array('127.0.0.1'); // Varnish $conf['cache_backends'] = 'sites/all/modules/varnish/varnish.cache.inc'; $conf['cache_class_cache_page'] = 'VarnishCache'; // Drupal 7 does not cache pages when we invoke hooks during bootstrap, this should be disabled. $conf['page_cache_invoke_hooks'] = FALSE; // Memcache $conf['cache_backends'] = 'sites/all/modules/memcache/memcache.inc'; $conf['cache_default_class'] = 'MemCacheDrupal'; $conf['cache_class_form'] = 'DrupalDatabaseCache'; // APC $conf['cache_backends'] = 'sites/all/modules/apc/drupal_apc_cache.inc'; $conf['cache_class_cache'] = 'DrupalAPCCache'; $conf['cache_class_cache_bootstrap'] = 'DrupalAPCCache'; //$conf['apc_show_debug'] = TRUE; // Remove the slashes to use debug mode.
Drupal must be made aware of Varnish, Memcache, and APC via ‘cache_backends’, cache bins can then be assigned to specific caching mechanisms, cache_page for Varnish, cache and cache_bootstrap for APC, and any other cache bins default to Memcache. Caching class_form in the database is required as the cache_form bin must be assigned to non-volatile storage.
Cache Expiration module settings can be activated and configured using ‘drush’ eg:
# drush vset varnish_cache_clear 2 # drush vset cache_lifetime 3600 # drush vset page_cache_maximum_age 3600
Drupal is then integrated with three primary caching mechanisms to enhance the performance and scalability of the website.