How to enable Memcached in Magento


Memcached is a free and open-source, high-performance, distributed memory caching system intended for use in speeding up dynamic web applications. Memcached can be used speeding up dynamic web applications by alleviating database load.

Magento supports the use of Memcached as a fast backend cache which can improve the speed significantly. Magento uses the Zend two-level cache to speed up page loads. Basically it is about having a small, but fast cache that is used for the first lookup, and if the data cannot be found in the first level it will be looked up in another cache that's usually bigger (mostly unlimited in size), but slower. This gives you advantages of both speed and size.

To enable Memcached in Magento, create a new file named memcached.xml and place it in the ./app/etc/ directory (next to your local.xml). By placing the Memcached config in a separate file, you can easily switch Memcached on/off by just renaming the file to memcached.xml.disabled. Place the following content in the file:

<config>
<global> <cache>
<backend>memcached</backend> <slow_backend>File</slow_backend> <fast_backend>Memcached</fast_backend> <fast_backend_options> <servers> <server> <host>unix:///home/<username>/.memcached/memcached.sock</host> <port>0</port> <persistent>0</persistent> </server> </servers> </fast_backend_options> <memcached> <servers> <server> <host>unix:///home/<username>/.memcached/memcached.sock</host> <port>0</port> <persistent>0</persistent> </server>
</servers>
</memcached>
</cache>
</global> </config>

Replace <username> with your account username. With the above settings, Memcached will be used as the first level (fast) cache and the filesystem as a second level (slow) cache. To eliminate the filesystem cache completely, you can add memcached as a slow backend provider as well, but please be aware this will break Magento's two-level caching and you will not be able to flush caches independently. It will also consume considerably more RAM on your Memcached instance.

Memcached is available on selected hosting plans or as a paid upgrade. Please contact our support team if you want to enable Memcached for your account.


Was this answer helpful?