Knowledge Base

How to configure Magento to use memcached

This article describes how to configure Magento to use memcached.

Memcached is an open-source memory object caching system that web sites can use to help accelerate page load times. Memcached works by caching in RAM frequently accessed data, such as the results of API calls, database calls, and more.

  • If you have a managed VPS or managed Discount Dedicated Server, please open a support ticket on the Customer Portal at https://berlin.hosting and request memcached for your system. We will install it for you.
  • If you have a semi-managed VPS, Cloud VPS, or semi-managed Discount Dedicated Server, you can install memcached yourself.
  • If you have a Cloudflare Web Hosting account, you should not follow the procedures in this article. Instead, use the L3 Optimized plugin to configure and manage memcached for your application.
  • Memcached is not supported on non-Cloudflare shared hosting accounts at this time.

Enabling memcached for Magento 2

To enable memcached for Magento 2, you need to change some settings in the env.php file. To do this, follow these steps:

  1. Using your preferred text editor, navigate to the directory where you installed Magento, and then open the app/etc/env.php file.
  2. Locate the following section in the env.php file:
     'session' =>
     array (
     'save' => 'db',
     ),
    
  3. Modify this section as follows:

     'session' =>
     array (
     'save' => 'memcached',
     'save_path' ==> '127.0.0.1:11211'
     ),
    
  4. Save your changes to the env.php file. Memcached is now enabled.

    For additional information about how to configure memcached with Magento 2, please visit http://devdocs.magento.com/guides/v2.0/config-guide/memcache/memcache_magento.html.

Enabling memcached for Magento 1.9 and older versions

To enable memcached for Magento 1.9 and older versions, you need to add some settings to the local.xml file. To do this, follow these steps:

  1. Using your preferred text editor, navigate to the directory where you installed Magento, and then open the app/etc/local.xml file.
  2. Add the following lines just before the closing </global> tag:
    <cache>
     <backend>memcached</backend>
     <memcached>
     <servers>
     <server>
     <host><![CDATA[127.0.0.1]]></host>
     <port><![CDATA[11211]]></port>
     <persistent><![CDATA[1]]></persistent>
     </server>
     </servers>
     <compression><![CDATA[0]]></compression>
     <cache_dir><![CDATA[]]></cache_dir>
     <hashed_directory_level><![CDATA[]]></hashed_directory_level>
     <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
     <file_name_prefix><![CDATA[]]></file_name_prefix>
     </memcached>
    </cache>
    
    If these lines are not contained in the <global> section, Magento will not use memcached.
  3. Save your changes to the local.xml file. Memcached is now enabled.

More Information