---
title: "Enabling Memcached on Cloud Platform"
date: "2024-02-14T06:18:38+00:00"
summary: "Boost your Drupal site's performance with Memcached on Cloud Platform. Learn how to install, configure, and optimize this powerful caching solution for faster page loads and improved scalability."
image:
type: "page"
url: "/acquia-cloud-platform/enabling-memcached-cloud-platform"
id: "c9eae00f-fec6-4afa-810e-40ec549f21bc"
---

Table of contents will be added

To enable Memcached on your website hosted by Cloud Platform, you must install the [Memcache API and Integration](https://www.drupal.org/project/memcache) 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](https://docs.acquia.com/acquia-cloud-platform/manage-apps/code/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](https://www.drupal.org/project/memcache) module. Although the [current Drupal version](https://docs.acquia.com/service-offerings/guide/software-life-cycle#supported-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](https://docs.acquia.com/acquia-cloud-platform/performance/memcached/locks).

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.
*   For FedRAMP-compliant customers in Cloud Next environments, the [Memcache Admin](https://www.drupal.org/project/memcache) module does not work properly. This happens because Cloud Next environments have the mcrouter component. For more information, visit [Memcached and Acquia hosting](https://docs.acquia.com/node/56428#FedRAMP-customers). As a workaround, use SSH to access an environment, and use the `acquia-memcache stats` CLI command to access Memcached statistics.

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:

### Cloud Platform

For environments running on [Cloud Next](https://docs.acquia.com/cloud-platform.html#cloud-next-benefits) technologies, ensure that you delete the older `cloud-memcache-d8+.php` file stored in the repository.

1.  Download the [Memcache API and Integration](https://www.drupal.org/project/memcache) module, and then add the module to your codebase in the `modules/contrib/memcache` directory. Acquia recommends that you use Composer to install the module:
    
        composer require drupal/memcache
    
    After you add the [Memcache API and Integration](https://www.drupal.org/project/memcache) module to your codebase through the preceding command, you do not need to additionally enable this module through the Drupal user interface or by using Drush.
    
2.  For Cloud Classic, do the following:
    1.  Add the Composer package that contains the Acquia Memcache settings to your project:
        
            composer require acquia/memcache-settings
        
    2.  For each website that requires Memcached, edit the [Cloud Platform database require line](/acquia-cloud-platform/acquia-require-line "Acquia require line") in `settings.php` with a PHP `require_once` statement, similar to the following example:
    3.      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; 
               } 
            }
        
        The same steps must be used for CD environments because CD environments are not supported in Cloud Next.  
          
        For Cloud Next, you do not need to add anything to your `settings.php` file as the configuration logic is already included in Cloud Next. If you already have code in `settings.php` that enables Memcache integration with Cloud Platform, you can opt to remove it. However, if you follow the preceding steps outlined for Cloud Classic, your code can run on a Cloud Classic environment, and is auto-disabled when running in a Cloud Next environment.
        
3.  Rebuild caches by running the following command, replacing `[example.com]` with the domain name of your website:
    
        drush cr --uri=[example.com]
    
4.  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](https://docs.acquia.com/support.html#contact-acquia-support).

### Site Factory

1.  Download the [Memcache API and Integration](https://www.drupal.org/project/memcache) module, and then add the module to your codebase in the `modules/contrib/memcache` directory. Acquia recommends that you use Composer to install the module:
    
        composer require drupal/memcache
    
    After you add the [Memcache API and Integration](https://www.drupal.org/project/memcache) module to your codebase through the preceding command, you do not need to additionally enable this module through the Drupal user interface or by using Drush.
    
2.  Download [`acsfd8+.memcache.settings.php`](https://docs.acquia.com/downloadable-resources#section-acsfd8memcachesettingsphp), and then add it to the `factory-hooks/post-settings-php` directory. For more information about the post-settings-php hook, see [Altering values in settings.php with hooks](https://docs.acquia.com/site-factory/extend/hooks/settings-php.html).
3.  Rebuild caches by running the following command, replacing `[example.com]` with the domain name of your website:
    
        drush cr --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](https://docs.acquia.com/support.html#contact-acquia-support).

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](https://docs.acquia.com/acquia-cloud-platform#cloud-next-benefits) 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:

### Cloud Platform

1.  Download the [Memcache API and Integration](https://www.drupal.org/project/memcache) module, and then add the module to your codebase in the `modules/contrib/memcache` directory. Acquia recommends that you use Composer to install the module:
    
        composer require drupal/memcache
    
    After you add the [Memcache API and Integration](https://www.drupal.org/project/memcache) module to your codebase through the preceding command, you do not need to additionally enable this module through the Drupal user interface or by using Drush.
    
2.  Download [`cloud-memcache-d7.php`](https://docs.acquia.com/node/55797#cloud-memcache-d7-php), and add the contents of the file to your website’s `settings.php` file, after the [Acquia database require line](/acquia-cloud-platform/acquia-require-line "Acquia 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](https://docs.acquia.com/support.html#contact-acquia-support).  
If your Drupal 7 site has issues with Memcached, add the following to your `settings.php` file:

    $conf['memcache_persistent'] = FALSE;

### Site Factory

1.  Download the [Memcache API and Integration](https://www.drupal.org/project/memcache) module, and then add the module to your codebase in the `modules/contrib/memcache` directory. Acquia recommends that you use Composer to install the module:
    
        composer require drupal/memcache
    
    After you add the [Memcache API and Integration](https://www.drupal.org/project/memcache) module to your codebase through the preceding command, you do not need to additionally enable this module through the Drupal user interface or by using Drush.
    
2.  Download [`acsfd7.memcache.settings.php`](https://docs.acquia.com/downloadable-resources#section-acsfd7memcachesettingsphp), and add it to the `factory-hooks/post-settings-php` directory. For more information about the post-settings-php hook, see [Altering values in settings.php with hooks](https://docs.acquia.com/site-factory/extend/hooks/settings-php.html).
3.  Edit the file, modifying the following lines if they do not correspond to the location of the [Memcache API and Integration](https://www.drupal.org/project/memcache) module in your codebase:
    
        $conf['cache_backends'][] = 'sites/all/modules/contrib/memcache/memcache.inc'; 
        $conf['lock_inc'] = 'sites/all/modules/contrib/memcache/memcache-lock.inc';
    
4.  Clear caches by running the following command , replacing `[example.com]` with the domain name of your website:
    
        drush cc all --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](https://docs.acquia.com/support.html#contact-acquia-support).

Allocating memory to Memcached
------------------------------

### Cloud Platform Enterprise

For environments running on [Cloud Next](https://docs.acquia.com/acquia-cloud-platform#cloud-next-benefits) technologies, you can adjust the memory allocated to Memcached as follows:

1.  [Sign in to the Cloud Platform user interface](https://docs.acquia.com/node/55875) and select your application and environment.
    
2.  Click **Actions** \> **Configure Environment**.
    
3.  Click **Advanced**.
    
4.  In **Memcached memory (MB)**, enter the amount of memory to allocate to Memcached. A value of 64 MB is the default value for applications running on Cloud Platform. However, you can increase the value depending on your application needs. Acquia recommends that you set a mid-range value of 128 MB or 256 MB. Thereafter, you can use the `acquia-memcache stats` command to determine if you need more or less memory depending on your usage and evictions.
    
5.  Click **Save**.
    

For environments running on the **Cloud Classic** infrastructure, you must [create a Support ticket](https://docs.acquia.com/support.html#contact-acquia-support) 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.

### Cloud Platform Professional

To allocate memory to Memcached on Cloud Platform Professional and enable it to run:

1.  [Sign in to the Cloud Platform user interface](https://docs.acquia.com/node/55875) and select your application and environment.
2.  In the navigation pane, click **Infrastructure**.
3.  In the card for the web infrastructure, click 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 Cloud Platform, but you may increase the value depending on the needs of your application.
5.  Click **Save**.

Using binary protocol
---------------------

### Cloud Classic

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.

### Cloud Next

The Memcache binary protocol is not supported in Cloud Next environments. If you enable binary protocol in Cloud Next environments, Drupal and PHP cannot communicate with Memcache servers. Therefore, the application fails to set or get cache items but does not return an error message.

Disabling auto-enablement of Memcached on Cloud Next
----------------------------------------------------

To disable Memcache integration with Drupal on Cloud Next, you can follow either of the following options:

*   Set the **Memcache memory limit** value to 0 through the Cloud Platform user interface or the Acquia Cloud API. This disables the Memcache service for every Drupal instance running within that environment.
    
*   Access the Drupal site’s `settings.php` file and add the `define('AH_NO_MEMCACHE_INCLUDE', 1);` statement. This only controls the automatic injection of the Memcache integration code, and is independent from turning the Memcache service on or off. If you use this method, you must do the following. If you do not do these steps, the system might use Memcache with non-recommended configurations, thereby causing issues.
    
    *   Disable the Drupal memcache module.
        
    *   Remove any integration code that adds the Memcache support from your `settings.php` file.
        

Note

You do not need to use both options on a single site or environment. Ensure that you test and use the option that best fits your use case. You can confirm whether Memcache is active using the CLI tool: `acquia-memcache`.