Drupal memcached | 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 Flex 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, Cloud VPS, or unmanaged Flex 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:
- Use your web browser to visit https://www.drupal.org/project/memcache.
- Under Downloads, download the .gz file to your computer.
- Log in to your Drupal site as the administrator.
- On the top menu bar, click Modules, and then click Install new module.
- Click Install. Drupal installs the memcached module.
, select the .gz file on your local computer, and then click
- Under Next steps, click Enable newly added modules. The Modules page appears.
- Scroll down to PERFORMANCE AND SCALABILITY, and then select the ENABLED check box next to the Memcache and Memcache Admin modules.
- On the top menu bar, click Configuration.
- Under SYSTEM, click Memcache.
- 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 .
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:
- Use your preferred text editor to open the sites/default/settings.php file.
- 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.
- Save your changes to the settings.php file. Memcached is now configured for Drupal.