Magento Memcached

Make Magento Memcached super easy with Redis Labs

Redis Labs’ products and services enable running Memcached buckets in a highly available and auto-scalable manner, with predictable top performance.

Redise Pack lets you install an enterprise grade Memcached cluster in your environment of choice, whether an on-premises data-center or your preferred cloud platform. It gives you full control of your data and configuration – no clustering or sharding knowledge required!

Memcached Cloud is a fully managed cloud service for hosting and running Memcached datasets in a highly available and scalable manner, with predictable and stable top performance. It provides a storage engine for standard Memcached, as well as in-memory replication and instant auto-failover within the same data center or across data centers. The service completely frees developers from dealing with nodes, clusters, scaling, data persistence issues or failure recovery.

Using Memcached with Magento

Magento can use Memcached both as a cache and as a session storage. We recommend you use a different Memcached bucket for each purpose.

To use Memcached as a cache and as a session storage for your Magento site, follow these steps:

  1. Make sure that your Magento server is installed with libmemcached and the PECL memcached extension.
  2. Log into Magento’s administration console and set default value of the Cookie Lifetime in the Magento Session Cookie Management to 31536000 in order to comply with following Memcached protocol specification about expiration times:

    Some commands involve a client sending some kind of expiration time
    (relative to an item or to an operation requested by the client) to
    the server. In all such cases, the actual value sent may either be
    Unix time (number of seconds since January 1, 1970, as a 32-bit
    value), or a number of seconds starting from current time. In the
    latter case, this number of seconds may not exceed 606024*30 (number
    of seconds in 30 days); if the number sent by a client is larger than
    that, the server will consider it to be real Unix time value rather
    than an offset from current time.

  3. Edit your site’s XML file, typically located at app/etc/local.xml, and add the following to the <global> block:
     <session_cache_limiter></session _cache_limiter>
     <session_save>
         <![CDATA[memcache]]>
     </session_save>
     <session_save_path>
         <![CDATA[tcp://hostname1:port1?persistent=1&weight=1&timeout=10&retry_interval=10]]>
     </session_save_path>
     <cache>
         <backend>
             memcached
         </backend>
         <slow_backend>
             database
         </slow_backend>
         <slow_backend_store_data>
             0
         </slow_backend_store_data>
         <memcached>
             <servers>
                 <server>
                     <host>
                         <![CDATA[hostname2]]>
                     </host>
                     <port>
                         <![CDATA[port2]]>
                     </port>
                     <persistent>
                         <![CDATA[1]]>
                     </persistent>
                     <weight>
                         <![CDATA[1]]>
                     </weight>
                     <timeout>
                         <![CDATA[10]]>
                     </timeout>
                     <retry_interval>
                         <![CDATA[10]]>
                     </retry_interval>
                     <status>
                         <![CDATA[1]]>
                     </status>
                 </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>
    

    To modify these settings so that your Memcached buckets are used:

    • Replace hostname1 with the hostname of your sessions bucket
    • Replace port1 with the port of your sessions bucket
    • Replace hostname2 with the hostname of your cache bucket
    • Replace port2 with the port of your cache bucket
      Displaying Memcached Howto – merged.md.

For more information on using Redis Labs’ products and services with Magento please see the Howto page.