The cache is probably one of the least understood parts of Magento. The purpose of this post is to help developers and store owners alike to better understand the limitations of the Magento Cache and how to overcome them.
The two most important concepts to wrap our heads around are IDs and Tagging.
By default the cache is stored in individual records under the var/cache/ folder. Most stores have a low amount of products and so the cache files will normally not go over a few thousand. It is when the number of products on your catalog is more than 20,000 or 30,000 that you can expect at least an equal amount of cache records.
These record file names are composed of an Id that is basically a unique string that identifies that particular record, combined with a tag that is used to identify the type of cache record.
In Magento we have the following cache types:
Configuration (non-layout XML files)
Blocks HTML output (Page blocks like headers, footers and callouts)
Magento uses Zend Cache as base for it’s own cache implementation and we can that the records use the prefix mage—— followed the the id, the tags and some other unique identifiers like the first 2 characters of the md5 hash of the path to the file. This pattern makes each record unique.
The slowest component on modern servers is usually the hard drive, the more I/O operations we add to our application in this case Magento the more will it take for it to respond and it will impact our application performance.
Knowing all of this, we can look to improve our store performance by reducing the number of read operations by keeping trimmed and clean cache. We have put together a module that will allow you to easily schedule several cache cleaning tasks.
CacheSweep allows you to schedule the following 5 tasks:
Sweep: This is the base method and it will delete all outdated cache records ideally you want to run this once per day.
SweepSystem: This method will flush the cache and its equivalent to running Flush Magento Cache, it will only flush the system cache records and ignore the images and css/js records
SweepAll: Is equivalente to the Flush Cache storate and will delete all cache types.
SweepStyle: Will refresh the css/js cache records
SweepMedia: Will refresh the image cache.
Each of these methods can be configured in the Magento backend as they take a simple cron expression as a parameter. In the next articles of this series we will dive into improving the store performance by setting up the cache and session folders on a tmpfs (Temporary Filesystem).