Magento can manage to cache at many levels in the system, most of which are transparent to developers who are not familiar with development in depth. As the complexity of your work with Magento has increased, it is imperative that you ultimately require caching yourself.
cache in Magento looks like many other systems that it stores a key-value. If we want to save
$data in the cache, we need to treat them with a name,
$key. When we need to retrieve $data later, we will do it with the same
$data stored in the cache can also be tagged with metadata. This allows the logical group of cache entries to delete bulk.
Magento provides an interface to enable, disable and empty the cache in the administration area. Each row in the "Cache Administration" table represents a cache tag. When updating one of these rows, we are deleting all the cache entries with a certain tag.
The Cache API
The model that controls our interface with the caching subsystem is Mage_Core_Model_Cache. Normally we access the cache through an already instanced object accessible in
The implementation of the cache memory is hidden for us, the interface that is provided to us consists (almost entirely) of the following methods:
save($value, $key, $tags = array(), $lifeTime=null)
clean($tags = array()
The actual backend used for caching can be a number of mechanisms from the built-in flat file approach (here’s a more efficient algorithm) to Memcached, APC, or even Redis for the hardcore.
Saving Data To Cache
$data = array(1,2,3,4,5,7,8); //any data which you want to save to cache
$id = 'my_mod_id_key'; //unique id for your cache data
$tags = array('collection'); //cache tags will be explain later in detail
$lifetime = false; //false means infinity, or you can specify number of seconds
$priority = 8; // number between 0-9, used by few backend cache models
Checking If Cache Is Enabled
Mage::app()->useCache('collection'); //check if cache group is enabled or not
What is Cache Tags
Magento has an important concept of cache tags in its caching system. Magento basically uses tags to group cache data and then we delete a specific tag group from admin, it removes all the data specific to that group of tags.
The different cache tags we have are "block_html", "collections", "config", "config_api", "config_api2", "eav", "layout", "translate", "mage"
These are the same configuration tags that we see when we go to System -> Cache Management
Then, when you delete a single magenta cache tag, it will erase all the cache data related to that tag.