Cloud Platform

Enabling Memcached on Cloud Platform

To enable Memcached on your website hosted by Cloud Platform, you must install the Memcache API and Integration module in your codebase, and configure the module for use.

When configuring your website to use Memcached, be aware of the following considerations:

  • Do not edit the memcache_key_prefix or memcache_servers settings, as Cloud Platform adds the correct values in Acquia-specific code defined by the Acquia require line, or otherwise available by default on Cloud Next. Altering these values can cause unexpected behavior.
  • If your website uses either automated testing or the memcache_admin submodule, you must enable the Memcache API and Integration module. Although the current Drupal version does not require you to enable the module, Acquia recommends you to enable the module to receive notifications about module updates.
  • For more information about stampede protection and database locking, see Enabling stampede protection and moving locks into memory.
Important
  • Test any of the procedures provided on this page on a non-production environment before implementing them on the production environment.
  • In Cloud Next, Acquia routinely optimizes the non-production environment to ensure high performance and enhanced scalability of your application. Therefore, your non-production memcache storage might be emptied from time to time. Production-level memcache workloads are notified in advance according to Acquia’s communication policies.

Configuration for the current Drupal version

For Memcached to function, you must provide additional configuration code that enables autoloading, and identifies Memcached as an alternative cache back-end.

To configure your website for Memcached, make the following changes to your codebase, depending on your subscription type:

For environments running on Cloud Next technologies:

  • Memcache runs per-environment instead of per-server and leverages mcrouter. Steps 2 and 3 are not required because Memcache configuration logic is included automatically. To exclude this logic on your environments, add the following line to your settings.php file:

    define('AH_NO_MEMCACHE_INCLUDE', 1);
    
  • If you have the older cloud-memcache-d8+.php file stored in this repository, ensure that you delete it.

 

  1. Download the Memcache API and Integration module, and then add the module to your codebase in the modules/contrib/memcache directory. We recommend to use Composer to install the module:

    composer require drupal/memcache
    
  2. Add the composer package that contains the Acquia Memcache settings to your project:

    composer require acquia/memcache-settings
    
  3. For each website that requires Memcached, edit the Cloud Platform database require line in settings.php with a PHP require_once statement, similar to the following example:

    if (file_exists('/var/www/site-php')) {
       require('/var/www/site-php/mysite/mysite-settings.inc');
    
       // Memcached settings for Acquia Hosting
       $memcache_settings_file = DRUPAL_ROOT . "/../vendor/acquia/memcache-settings/memcache.settings.php";
       if (file_exists($memcache_settings_file)) {
         require_once $memcache_settings_file;
       }
    }
    
  4. Rebuild caches by running the following command, replacing [example.com] with the domain name of your website:

    drush cr --uri=[example.com]
    
  5. Truncate all cache_ tables in the database for the website.

Memcache is now enabled for your website. Continue to read the next section.

If you need assistance, create a Support ticket.

Configuration for Drupal 7

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.

Note

For Drupal 7 environments running on Cloud Next technologies, step 2 isn’t required because Memcache configuration logic is included automatically. To exclude this logic on your environments, add the following line to your settings.php file:

define('AH_NO_MEMCACHE_INCLUDE', 1);

 

To configure your Drupal 7 website for Memcached, make the following changes to your codebase, depending on your subscription type:

  1. Download the Memcache API and Integration module, and then add the module to your codebase in the sites/all/modules/contrib/memcache directory.
  2. Download cloud-memcache-d7.php, and add the contents of the file to your website’s settings.php file, after the Acquia database require line.
  3. Clear caches by running the following command, replacing [example.com] with the domain name of your website:

    drush cc all --uri=[example.com]
    
  4. Truncate all cache_ tables in the database for the website.

Memcache is now enabled for your website. If you need assistance, create a Support ticket.

Allocating memory to Memcached

For environments running on Cloud Next technologies, you can adjust the memory allocated to Memcached as follows:

  1. Sign in to the Cloud Platform user interface and select your application and environment.

  2. Click Actions > Configure Environment.

  3. Click Advanced.

  4. Scroll to the bottom of the page and select Memcached.

    You must have at least 512 MB in Memcached. However, for enhanced performance, Acquia recommends that you have 1 GB for Drupal 10 applications.

  5. Click Save.

For environments running on the Cloud Classic infrastructure, you must create a Support ticket to request that your Memcached memory allocation be modified. Larger amounts of memory can be allocated to Cloud Classic environments with dedicated Memcached infrastructure. Contact your Acquia account team for more information about this advanced configuration.

Using binary protocol

You can leverage the Memcache binary protocol in Cloud Classic environments. However, Acquia does not recommend its use.

To use this protocol in Cloud Classic environments, ensure that you enable the Memcached::OPT_TCP_NODELAY flag in Memcache options to avoid slow fetches of empty cache items.