# Configuring Drupal to use memcached

> Configure Drupal to store cache data in Memcached by installing the module and updating settings.php, to cut database queries.

Source: https://helpcenter.ruachost.com/apps/drupal/configuring-drupal-to-use-memcached/

**Memcached** is a high‑performance, distributed memory caching system that stores frequently accessed data in RAM. Configuring Drupal to use Memcached can significantly improve site performance by reducing database queries. On **ruachost.com**, Memcached is available on Managed VPS accounts. [Contact Ruachost support](https://dashboard.ruachost.com/submitticket.php) to check availability on your shared hosting plan.

## Why Use Memcached with Drupal?

- Faster page load times by caching queries in memory.
- Reduced database load.
- Improved scalability for high‑traffic sites.
- Enhanced performance for APIs and dynamic content.

## Steps to Configure Drupal to Use Memcached

### Step 1: Install Dependencies and Module

1. Log in to your server via **SSH**.
2. Navigate to your Drupal installation directory.
3. Run the following commands:

   ```bash
   composer require drupal/memcache
   ```
4. Copy the example Memcached services file:

   ```bash
   cp modules/contrib/memcache/example.services.yml sites/default/memcache.services.yml
   ```
5. Log in to Drupal as an administrator.
6. Go to **Extend → List tab → Performance**.
7. Check the box next to **Memcache** and click **Install**.
8. You should see a confirmation message: *Module Memcache has been enabled*.

### Step 2: Configure Drupal Settings

1. Open the `sites/default/settings.php` file in a text editor.
2. Add the following configuration based on your hosting type:

   ### For Shared Hosting Accounts (where available)

   ```
   $settings['memcache']['servers'] = ['/home/username/.memcache/memcached.sock' => 'default'];
   $settings['memcache']['bins'] = ['default' => 'default'];
   $settings['cache']['default'] = 'cache.backend.memcache';
   $settings['container_yamls'][] = 'sites/default/memcache.services.yml';
   ```

   *(Replace* `username` *with your account username.)*
3. Save the file.

### Step 3: Verify Memcached Integration

1. In the Drupal admin menu, go to **Reports → Memcache**.
2. Look for the message: *Connected, using the Memcache backend*.
3. Review Memcached cache statistics to confirm proper integration.

## Important Notes

- Memcached is not available on every shared hosting plan. [Contact Ruachost support](https://dashboard.ruachost.com/submitticket.php) to confirm availability for your account.
- Always back up your site before making configuration changes.
- For advanced options, see the `modules/contrib/memcache/README.md` file.
