Information for: DEVELOPERS   PARTNERS

Enabling Memcached on Acquia Cloud

About Memcached

Memcached is not available for use with Acquia Cloud Free.

Although using Memcached on your website requires you to include the Memcache API and Integration module in your codebase, Drupal 8 does not require you to enable the module before deploying the changes to settings.php described in Configuring your codebase.

Both Drupal 7 and Drupal 8 require you to enable the module to use the memcache_admin submodule or to run the automated tests included with the module.

Important

If you are installing the module on a Drupal 7 website, you must enable the module before modifying settings.php, or you will receive a ServiceNotFoundException: error message.

To enable Memcached on your servers, complete the following steps:

  1. Allocate memory to Memcached according to your Acquia Cloud subscription type:
  2. Download, install, and enable the Memcache API and Integration module on your Acquia Cloud application. After you enable the module, you will receive notifications for when you must update the module, and can view your application’s Memcached statistics. For information about installing a module in Drupal 8, see Installing a Drupal 8 module.
  3. Add configuration code as described in the Configuring your codebase section of this page, depending on your installed version of Drupal:

After you publish the code changes, Memcached is enabled.

Enabling Memcached on Acquia Cloud Professional

This section applies only to Acquia Cloud Professional.

To allocate memory to Memcached on Acquia Cloud Professional and enable it to run, use the following procedure:

  1. Sign in to Acquia Cloud and select your application, and then select the environment.

  2. In the left menu, click Servers.

  3. In the card for the web server, click the Configure link.

    The Acquia Cloud user interface displays the Configure link

  4. In the Memcached memory (MB) field, enter the amount of memory to allocate to Memcached. A value of 64 MB is the default value for applications running on Acquia Cloud, but you may increase the value depending on the needs of your application.

  5. Click Save.

Configuring your codebase

As part of enabling Memcached, add the following configuration code to your settings.php file immediately after the Acquia database require statement, depending on your installed version of Drupal:

Note

Do not edit the memcache_key_prefix or memcache_servers settings in settings.php. Acquia Cloud adds the correct values for these directives in Acquia-specific code called by settings.php. If you enter the values manually, unexpected behavior can result.

Configuration for Drupal 8

In Drupal 8, the memcache module is not required to be enabled as long as the memcached server is available in your subscription. By auto-loading Memcached in this manner, Memcached can be used as an alternative cache backend during Drupal’s website installation process, preventing some known configuration management and profile inheritance issues.

To configure your Drupal 8 website for Memcached, make the following changes to your codebase:

Important

The following code requires version 8.x-2.0-alpha7 of the memcache module. Because this module is an alpha release, Acquia recommends you test the module in a non-production environment before you try to use the module with your production websites. Failing to do so could cause unplanned website outages or data loss.

  1. Download cloud-memcache-d8.php and add its contents to your website’s settings.php file immediately following the Acquia database require statement. You can add the contents to the file either directly, or by inserting them with a PHP include() or require() statement.

  2. Edit the following line in the code to provide the path to the memcache Drupal module in your codebase:

    // MODIFY THIS NEXT LINE depending on the location of the memcache
    // Drupal module in your codebase.
    $memcache_services_yml = DRUPAL_ROOT . '/modules/contrib/memcache/memcache.services.yml';
    

Configuration for Drupal 7

The following configuration settings cause Drupal to use Memcached instead of MySQL for data normally stored in database caches, and ensures the cache_form table is assigned to non-volatile storage. For more information about stampede protection and database locking, see Enabling stampede protection and moving locks into memory.

To configure your Drupal 7 website for Memcached, download this example cloud-memcache-d7.php file and add the contents of the file to your website’s settings.php file, modifying the cache_backends path in this line (if needed) to point to the location of the memcache module in your application’s docroot:

$conf['cache_backends'][] = 'sites/all/modules/contrib/memcache/memcache.inc';