How to configure Drupal to use memcached

This article describes how to configure Drupal to use memcached.

Memcached is an open-source memory object caching system that web sites can use to help accelerate page load times. Memcached works by caching in RAM frequently accessed data, such as the results of API calls, database calls, and more.

  • If you have a managed VPS or managed Dedicated Server, please open a support ticket on the Customer Portal at https://my.a2hosting.com and request memcached for your system. We will install it for you.
  • If you have an unmanaged VPS or unmanaged Dedicated Server, you can install memcached yourself.
  • If you have a Turbo Boost or Turbo Max Web Hosting account, you should not follow the procedures in this article. Instead, use the A2 Optimized plugin to configure and manage memcached for your application.
  • Memcached is not supported on non-Turbo shared hosting accounts at this time.

Installing the memcached module

After memcached is installed on your system, you need to install a module so Drupal can access and use it. To do this, follow these steps:

  1. Use your web browser to visit https://www.drupal.org/project/memcache.
  2. Under Downloads, download the .gz file to your computer.
  3. Log in to your Drupal site as the administrator.
  4. On the top menu bar, click Modules, and then click Install new module.
  5. Click Browse, select the .gz file on your local computer, and then click Install. Drupal installs the memcached module.
  6. Under Next steps, click Enable newly added modules. The Modules page appears.
  7. Scroll down to PERFORMANCE AND SCALABILITY, and then select the ENABLED check box next to the Memcache and Memcache Admin modules.
  8. Click Save configuration.
  9. On the top menu bar, click Configuration.
  10. Under SYSTEM, click Memcache.
  11. If you want to display memcached-related statistics at the bottom of each page, select the Show memcache statistics at the bottom of each page check box, and then click Save configuration.
    By default, only the administrator can view these statistics, which include fetch times (in milliseconds), total number of cache hits and misses, and more.

Configuring memcached settings

After you install and enable the memcached module, you are ready to configure Drupal to actually use memcached. To do this, follow these steps:

  1. Use your preferred text editor to open the sites/default/settings.php file.
  2. Copy the following text and paste it into the settings.php file:
    $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
    $conf['lock_inc'] = 'sites/all/modules/memcache/memcache-lock.inc';
    $conf['memcache_stampede_protection'] = TRUE;
    $conf['cache_default_class'] = 'MemCacheDrupal';
    
    // The 'cache_form' bin must be assigned to non-volatile storage.
    $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';
    
    // Don't bootstrap the database when serving pages from the cache.
    $conf['page_cache_without_database'] = TRUE;
    $conf['page_cache_invoke_hooks'] = FALSE;
    
    This configuration sets up one memcached instance that stores all Drupal caches in memcache except for cache_form. For additional memcached configuration examples, see the sites/all/modules/memcache/README.txt file.
  3. Save your changes to the settings.php file. Memcached is now configured for Drupal.

More Information

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.