Increase server performance with Magento Caching
Magento Uses multi level of caching based on Zend framework. Most of which are transparent to developers.
From very top Magento stores cache data in two different types of back end.
i) Very fast cache like APC, Memcached, Solr, Redis..etc.
ii) A slow like file system.
Each cache medium like APC, Memcached, Redis uses their own strategy to store data uses key value as backend. The data are stored in cache with meta data. These meta data are used for mass deletion of cache values. These cachings are controlled in magento through Cache API only.
The Cache API
The caching system in mangento is controlled by Mage_Core_Model_Cache. Which is typically access the cache through an already instantiated object accessible at Mage::app()->getCache().
The implementation of these cache are hidden from us, but their actual implementation are done through below methods only.
save($value, $key, $tags = array(), $lifeTime=null)
clean($tags = array()
See Magento Caching Example in action
If you want to see how magnto caching works simply use
$cache = Mage::app()->getCache();
here $cache instantiate the object of magento cache and with this object you can store your value into cache itself
$cache->save(date("y-m-d"), "nice_date", array("nice_cache"), 10); $cache->save("hello cache world - " . time(), "nice_hellocacheworld", array("nice_cache"), 60*60);
With the above example I have instructed the cache to store the value of the current date with the $key nice_date. I’ve also stored the phrase hello cache world – 601992000 (any timestamp) with the $key nice_hellocacheworld .
To fetch the value of a key from cache, we simply use:
To remove individual values from the cache, we use:
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022