---
title: "Memcached and Acquia hosting"
date: "2024-02-14T06:18:38+00:00"
summary: "Optimize Drupal performance with Acquia's Memcached solution. Learn about key components, memory management, and cache bins for faster sites."
image:
type: "page"
url: "/acquia-cloud-platform/memcached-and-acquia-hosting"
id: "7f1cc5fa-df57-4b2c-bdf9-e46cad00e6ba"
---

Table of contents will be added

Acquia’s Memcached solution is comprised of the following four major pieces: The Memcached daemon, the PHP Memcached library, the Memcache API and Integration module, and Drupal core.

For introductory information about Memcached, see [Using Memcached](/acquia-cloud-platform/performance/memcached). For instructions on how to enable Memcached, see [Enabling Memcached on Acquia Cloud](/acquia-cloud-platform/performance/memcached/enable).

**For FedRAMP customers**:

![cloud-platform_stack.png](https://acquia.widen.net/content/63ebdf99-79dd-4b52-ac98-dfd92f6dcf01/web/cloud-platform_stack.png?h=480&itok=phM2hIiV)

**For non-FedRAMP customers**:

![cloud-platform_memcache-stack-non-fedramp.png](https://acquia.widen.net/content/e3b7a66f-5373-4d91-b161-e2a5d63529ea/web/cloud-platform_memcache-stack-non-fedramp.png?h=401&itok=wcE0_ouA)

Memcached service
-----------------

The Memcached daemon is installed as a service with several components that work together to ensure stability and uptime for a website.

### Key/Value storage

Memcached is a _key-value store_, which is a data storage paradigm designed for storing, retrieving, and managing associative arrays—commonly known as a _hash_. This contrasts with relational database object models that enable advanced concepts such as mapping and data types.

### Commands

The Memcached service includes the following commands for handling data:

*   `get` - Retrieve an existing item from storage.
*   `set` - Save a new item to storage.
*   `flush_all` - Mark an item as `expired` so that it cannot be retrieved. This method pushes the current item to the front of the line, to be replaced by the next cacheable item. It does not free the memory used by that item.
*   `delete` - Remove an item from storage.
*   `stats` - Query the service for aggregated data about the objects saved to storage.

Note

Environments on [Cloud Next](/acquia-cloud-platform) technologies have access to alternatives to mcstat with these syntaxes:

*   `acquia-memcache stats`
*   `acquia-memcache flush_all`

### Memory partitioning

When the Memcached service is started, it reserves memory for object storage (by default, 64 MB). The memory allocated is divided into 1MB _pages_, which by default provides 64 pages. Memcached initializes a memory organization concept called a _slab_ class on startup. A slab defines the number of items (chunks) which can be inserted into a 1MB memory page. By dividing 1MB by that number of chunks, you can determine that slab’s chunk size.

By default, Memcached creates 42 slabs and assigns a single page to each. Each successive slab holds fewer, larger chunks based on the _factor_ (by default, 1.25). In the following sample representation of slabs, notice that the item size (or chunk size) increases by a factor of 1.25 from the second to the third slab:

    #   Item_Size  Max_age   Pages   Count   Full?  Evicted Evict_Time OOM
                            2      120B   1168824s       1     170      no        0        0    0
                            3      152B   1831103s       1     196      no        0        0    0
                            4      192B   1847211s       1     988     yes       30     9183    0
                            ...
                            36    246.8K     27236s       6      21     yes        7     2676    0
                            37    308.5K      1224s       2       3     yes       91    29174    0
                            ...
                            40    602.5K      1696s      11       4     yes        0        0    0
                            41    753.1K        64s       4       1     yes        6       35    0
                            42   1024.0K     44944s       5       1     yes       20        1   20

Memcached saves items by evaluating an item’s size, and then writing it to a slab. In the previous example, note that slab 36 contains items that range in size from 246.8KB to less than 308.5KB.

When a slab cannot fit a new item and there is additional memory available to Memcached, a new page will be assigned to the slab. In the previous example, slab 36 can contain at most four items, but, depending on the items’ size, may contain only three items:

*   If objects are 248KB, four items equals 992KB, which is less than 1MB.
*   If objects are 300KB, because four items equals 1.2MB, after three items a new page is created.

When the `set()` method is called, Memcached determines the size of the object, and then locates the slab with the appropriate memory allocation.

### Memory management

Each Memcached node is configured to manage its memory with Least Recently Used (LRU) prioritization. The nodes oversee their local slab arrays, producing a list of candidates for removal. When a new item is assigned to a full slab and there are no free pages to assign to that slab, the full slab evicts the LRU item from the same slab. This is both healthy and accepted behavior—assuming that the objects being evicted are outdated and due to be safely removed.

### Scaling

Memcached does not internally provide mechanisms for adding capacity through additional processes. Instead, this functionality is handled entirely by an external client, such as the [PECL Memcache extension for PHP](/acquia-cloud-platform/performance/memcached/pecl).

High availability and Memcached
-------------------------------

### Cloud Classic

An item cached by Memcached is stored in a specific location on a single infrastructure, even if your subscription includes multiple Memcached infrastructure.

If a Memcached infrastructure fails, its cached items will no longer be available, and requests for these items will be rerouted to the database layer of your application. Memcached cannot detect failed infrastructure, and will continue to route requests to all infrastructure, resulting in slow or failed requests until the failed infrastructure is repaired or removed from service. Although healthy Memcached infrastructure in your subscription will continue to respond normally, responses may slow or fail if the data source becomes overloaded.

If Memcached must be restarted on a single node, all Memcached nodes for that cluster must be reset. If this doesn’t occur, `multi_item` objects contain incomplete data.

### Cloud Next

The Memcache service can accept requests from any PHP application. Data in Memcache might be split across multiple Memcache servers to ensure scalability for your applications. Memcached nodes might be replaced during resource usage optimization processes, feature releases, or security updates. Feature releases or security updates clear the entire cache. All Memcached nodes operate with the Memcached memory limit configured on a given environment.

Cache bins in the current Drupal version
----------------------------------------

You can enable Memcached for a site hosted on Cloud Platform by following the steps mentioned on [Enabling Memcached on Cloud Platform](/acquia-cloud-platform/enabling-memcached-cloud-platform "Enabling Memcached on Cloud Platform"). After you complete those steps, the system configures your website to use Memcached for most of the Drupal cache bins, except the following: 

*   The **bootstrap** bin contains information for most Drupal application requests, and is rarely invalidated.
*   The **discovery** bin contains discovery data for plugins; Views data; or YAML-discovered data, such as library information.
*   The **config** bin contains configuration information provided by modules enabled on your website.

 The preceding bins use a [ChainedFast Cache backend](https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Cache%21ChainedFastBackend.php/11.x) that couples an inconsistent, fast, and local cache (APCu) with a distributed and consistent Memcache backend.

When using Memcache, some of the Cache bins that use Memcached as the backend include:

*   The **data** bin contains data that can vary both by path or by context.
*   The **render** bin contains cached HTML strings like cached pages and blocks.

For advanced information about cache bins, see the [configuration section of the Drupal Cache API documentation](https://api.drupal.org/api/drupal/core%21core.api.php/group/cache/9.0.x#configuration) on Drupal.org.

Important

Content Hub 2.x requires the Depcalc module which needs to use the database backend. This is implemented automatically if you follow the steps mentioned on [Enabling Memcached on Cloud Platform](/acquia-cloud-platform/enabling-memcached-cloud-platform "Enabling Memcached on Cloud Platform").

    $settings['cache']['bins']['depcalc'] = 'cache.backend.database';