Feature #211

Adding Memcache Support to Magento

Added by Daniel Curtis about 8 years ago. Updated over 6 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:
0.50 h
Spent time:


With the addition of a load balancer and multiple instances of the same site on different servers, I needed to have session data stored at a central location to be accessed by each web server. Currently I use memcached, which Magento supports through the Zend Framework. So adding support is done by making sure that the php.ini has the following information:

session.save_handler = memcached
session.save_path = "tcp://yourMemcachedIP:11211"

This sets PHP to use memcached for session storage.

Next the app/etc/local.xml in the Magento directory must be edited to define memcached storage:

    <session_save><![CDATA[memcache]]></session_save> <!-- db / memcache / empty=files -->
    <session_save_path><![CDATA[tcp://X.X.X.X:11211?persistent=1&weight=2&timeout=10&retry_interval=10]]></session_save_path><!-- e.g. for memcache session save handler tcp:// -->
    <session_cache_limiter><![CDATA[private]]></session_cache_limiter><!-- see for possible values -->
        <backend>memcached</backend><!-- apc / memcached / xcache / empty=file -->
        <slow_backend>database</slow_backend> <!-- database / file (default) - used for 2 levels cache setup, necessary for all shared memory storages -->
        <slow_backend_store_data></slow_backend_store_data> <!-- 1 / 0 (default) - used for 2 levels cache setup, sets whether store data in db slow cache backend -->
        <auto_refresh_fast_cache>1</auto_refresh_fast_cache> <!-- 1 / 0 (default) - used for 2 levels cache setup, sets whether refresh data in fast cache backend -->
        <memcached><!-- memcached cache backend related config -->
            <servers><!-- any number of server nodes can be included -->

And finally make sure to have the internal Cache Management turned off


Updated by Daniel Curtis about 8 years ago

  • Description updated (diff)

Updated by Daniel Curtis about 8 years ago


The above configuration is intended for a memcache server. The configuration for a memcached server with support for session management looks more like this:

<!-- Optimize sessions for Memcached use -->

<!-- Optimize cache for Memcached use -->

I had issues getting this to work by having the configuration parameter persistent as 1. To fix it I disabled persistent by switching the parameter to 0.


Updated by Daniel Curtis over 6 years ago

  • Project changed from 6 to Website Hosting

Also available in: Atom PDF