magentosessioncachingmemcachedscalr

Memcached Not Working in Magento


I have a cluster set-up on AWS using Scalr.net. I am running Magento CE 1.7 on:

The intent is to store files caches and session caches on the memcached server. I have set up magento local.xml as so:

<session_save><![CDATA[memcache]]></session_save>
<session_save_path><![CDATA[tcp://XX.XX.XX.XX:11211?persistent=1&weight=2&timeout=10&retry_interval=10]]></session_save_path>
<session_cache_limiter><![CDATA[]]></session_cache_limiter>
<cache>
        <backend>memcached</backend>
        <slow_backend>database</slow_backend>
        <slow_backend_store_data><![CDATA[]]></slow_backend_store_data>
        <auto_refresh_fast_cache><![CDATA[]]></auto_refresh_fast_cache>
        <lifetime>259200</lifetime>
    <backend_options>
    <servers>
    <server>
        <host><![CDATA[XX.XX.XX.XX]]></host>
        <port><![CDATA[11211]]></port>
        <persistent><![CDATA[0]]></persistent>
        <weight><![CDATA[2]]></weight>
        <timeout><![CDATA[10]]></timeout>
        <retry_interval><![CDATA[10]]></retry_interval>
        <status><![CDATA[1]]></status>
    </server>
    </servers>
        <compression><![CDATA[0]]></compression>
    </backend_options>
</cache> 

But Memcached is not working. Here are my stats:

root@ec2-XX.XX.XX.XX:~# telnet ip-XX.XX.XX.XX 11211
Trying XX.XX.XX.XX...
Connected to ip-XX.XX.XX.XX.ec2.internal.
Escape character is '^]'.
stats
STAT pid 1086
STAT uptime 79364
STAT time 1352912987
STAT version 1.4.2
STAT pointer_size 64
STAT rusage_user 2.340000
STAT rusage_system 0.000000
STAT curr_connections 5
STAT total_connections 11
STAT connection_structures 6
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT bytes_read 28
STAT bytes_written 2194
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
END

Also, the site throws these errors:

a:4:{i:0;s:29:"cache_dir must be a directory";i:1;s:1097:"#0 /var/www/includes/src/Zend_Cache_Backend_File.php(154): Zend_Cache::throwException('cache_dir must ...')
#1 /var/www/includes/src/Zend_Cache_Backend_File.php(121): Zend_Cache_Backend_File->setCacheDir('')
#2 /var/www/includes/src/__default.php(60504): Zend_Cache_Backend_File->__construct(Array)
#3 /var/www/includes/src/__default.php(60445): Zend_Cache::_makeBackend('File', Array, true, true)
#4 /var/www/includes/src/Mage_Core_Model_Cache.php(124): Zend_Cache::factory('Varien_Cache_Co...', 'File', Array, Array, true, true, true)
#5 /var/www/includes/src/__default.php(23463): Mage_Core_Model_Cache->__construct(Array)
#6 /var/www/app/Mage.php(462): Mage_Core_Model_Config->getModelInstance('core/cache', Array)
#7 /var/www/includes/src/__default.php(20134): Mage::getModel('core/cache', Array)
#8 /var/www/includes/src/__default.php(20028): Mage_Core_Model_App->_initCache(Array)
#9 /var/www/includes/src/__default.php(20070): Mage_Core_Model_App->baseInit(Array)
#10 /var/www/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#11 /var/www/index.php(87): Mage::run('', 'store')
#12 {main}";s:3:"url";s:1:"/";s:11:"script_name";s:10:"/index.php";}

if I include the following in backend options:

        <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>

Your help will be greatly appreciated. Thanks.


Solution

  • My local.xml has a <memcache> section inside of <cache> and the <backend>Memcached</backend> is capitalized:

        ...
        <cache>
                <backend>Memcached</backend>
                <slow_backend>database</slow_backend>
                <backend_options>
        ...
                </backend_options>
                <memcached>
                        <servers>
                                <server>
                                        <host><![CDATA[127.0.0.1]]></host>
                                        <port><![CDATA[11211]]></port>
                                        <persistent><![CDATA[0]]></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>
        ...
    

    Also, you will want two instances of memcache running, i.e. use port 11211 for sessions and 11212 for cache. I have two files: /etc/memcache_1.conf and /etc/memcache_2.conf that setup these different instances. That way when you clear the cache it won't log out all of your users!