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:
<cache> <backend>memcached</backend> <slow_backend>database</slow_backend> <slow_backend_store_data>0</slow_backend_store_data> <auto_refresh_fast_cache>0</auto_refresh_fast_cache> <memcached> <servers> <server> <host><![CDATA[127.0.0.1]]></host> <port><![CDATA[11211]]></port> <persistent><![CDATA[1]]></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>
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:
<session_save><![CDATA[memcache]]></session_save> <session_save_path><![CDATA[tcp://127.0.0.1:11212?persistent=1&weight;=2&timeout;=10&retry;_interval=10]]></session_save_path> <session_cache_limiter><![CDATA[public,must-revalidate]]></session_cache_limiter>
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!