The default setting on Magento enables it to use a two level cache backends from the zend framework. This means that the system stores its cache records in two different backends where one is the faster and yet limited one while the other is slower. The faster alternatives include APC and Memcached while the file system is the slow one. The backends have unique features that make choosing them a rather important part of the process. The APC and Memcached for example do not support grouping the cache entries, as they are key/value cache backends. The files system and Redis however allow you to group the cache entries.
The two level caching system and how it works:
The Magento default setting has it storing its cache entries in the file system and thus they can be found in var/cache/. The file system works just fine for websites that do not have much traffic but once the requests increase you may be unable to read and write in the file system. In this case however, the caches are organized by groups and may thus be easy to read and write. The main advantage of the file system is that it is in the default setting and thus you do not have to install any additional programs to operate it.
The disadvantage on the other hand is that if you want to clear cache Magento will have to go through each cache group file by file to check the tags before clearing since it clears by tags. Thus if you have too many cache entries it could take forever for Magento to actually clear them all. In order to get the system to work more effectively you may want to use SSD instead of the usual hard disk. Also, you could put the var/cache/ directory in tmpfs.
The Alternative PHP Cache (APC) is a key/value cache, that is free and open meaning that it is dedicated to provided an open framework where the PHP intermediate code can undergo optimization. The main advantage of this caching alternative is the speed at which it works. The APC allows you to have duplicate PHP script extensions running more efficiently in an automated system. It also enables you to store application data.
The disadvantage on the other hand is that is does not support tagging and as such you will end up having a slow system as is with the file system. The APC also requires installation of the PHP APC extension on the server as it is not an automatic default setting. For this alternative to perform better you may need to give it a larger memory space by the parameter “apc.shm_size”. You could also improve it by following the prompts below.
Settings for php.ini
apc.enabled = 1
apc.optimization = 0
apc.shm_segments = 1
apc.shm_size = 768M
apc.ttl = 48000
apc.user_ttl = 48000
apc.num_files_hint = 8096
apc.user_entries_hint = 8096
apc.mmap_file_mask = /tmp/apc.XXXXXX
apc.enable_cli = 1
apc.cache_by_default = 1
apc.max_file_size = 10M
apc.include_once_override = 0
This is a high performance caching system that has a well distributed memory. This system operates by alleviating the database load thus making it very useful for busy websites that use many web applications. Its main advantage is that it is very fast, compared to the other caching backends. It however does not support tagging and will thus give you a very slow file system. To work, it will require a Memcached server and its PHP extension.
<backend>memcached</backend><!-- apc / memcached / empty=file -->
<memcached><!-- memcached cache backend related config -->
<servers><!-- any number of server nodes can be included -->
This particular backend allows for a redis server to be your central storage. It also allows tagging, making it the only backed that will eliminate the slow file system. This means that it is an ideal backend especially for situations where you are using multiple web servers. The main advantage is the elimination of a slow file system and the fact that it has passed numerous trials on busy websites. It is very fast, stable and effective even with a record of half a million visitors per day.
To use this backend, you must install Redis on the server and have the PHP extension phpredis. You also have to install the Magento extension “Cm_Cache_Backend_Redis”
First install redis version 2.4+, then install phpredis. After this, you have to install the magento extension “Cm_Cache_Backend_Redis” and finally edit your app/etc/local.xml
<server>127.0.0.1</server> <!-- or absolute path to unix socket -->
<compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy -->
You will also need to install phpRedisAdmin, a useful tool that manages Redis databases.
If you are working with a small cache size then the APC and a file system will work best as your second level cache. This will however be optimized if you use the SSD and have your directory in tmpfs. But for bigger stores with larger cache sizes redis is the best option you could get.