How to configure Magento to use Memcached

In this tutorial we will explain how to configure your Magento application to use Memcached. The Magento application natively supports Memcached. This means that you just need to enable this option. In order to do this you have to edit the Magento XML configuration file - local.xml.

This file is stored inside the web root folder. For example, if your website is accessible at:

http://domain.com/magento

this means that the local.xml file is in your public_html/magento/app/etc folder. In order to edit the file you can use the cPanel File Manager.

Open the file and find the following line of code (usually this is also the end of the file):

</config>

Right before this line add the following lines:

<cache>
<backend>
memcached</backend>
<!-- apc / memcached / empty=file -->
<memcached>
<!-- memcached cache backend related config -->
<servers>
<!-- any number of server nodes can be included -->
<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>

Please note that you should replace port number 11211 with the correct port number for your hosting account.

For more details how to find out the correct port please check the following tutorial:

Enable Memcached from cPanel

After that save the file. The following screenshot shows how to edit the file via the cPanel File Manager -> Code Editor Tool:

That's it - your Magento application is now correctly configured. From now on the e-commerce app will use Memcached to cache certain API calls, database calls and objects.