Magento and Memcached: Faster Caching for Your Store

Magento and Memcached: Faster Caching for Your Store pixelwork

Magento and Memcached: Faster Caching for Your Store

As your customers navigate through your Magento store, Magento often writes various information to disk in an effort to present a smoother and more pleasant experience to the end user. These objects are often various central systems, popular PHP calls and various other blocks of information that the Magento system receives many times from the client. It is much faster for Magento to store these requests in an on-drive caching system than to have to rebuild the information with each request.

However, disk access times are a major drag on server resources. While cache retrieval is certainly faster than code request processing, drive access is slower than other storage media available to a web server...namely RAM.

Magento has a built-in backend to deliver your cache to other cache engines, such as memcached and redis. For the purposes of this blog post, we will assume that you have chosen memcached for your Magento cache backend and already have an instance installed and ready to use.

Memcache is a system of memory cache which contains database objects and data in RAM, so that the system does not have to make slow calls to the database to retrieve the requested information.

The Magento cache configuration is located in the app/etc/local.xml file located in the root of the Magento installation directory. You will need to place the following code block in the tag from local.xml file:




















The sections and They should point to the IP address of the host that is running the memcached instance (usually localhost) and the port that the memcached process is listening on. This can be configured during the configuration of the memcache daemon.

User session information is also susceptible to the latency of drive access times, as is cache memory. Magento also offers a memcached backend for storing this data in RAM. It is highly recommended that Magento session caching and caching be done using two separate memcached instances. They can run on the same host, but on different ports.

Add the following code block to the local.xml file in the section to enable memcached session caching once a second memcached instance has been created and running:




In the block Above, the memcached instance for our session data is running on the same host (localhost), but on a different port (11212) than our Magento cache (port 11211).

Implementing these two caching systems can greatly speed up the response time for your end users while shopping in your store!