PUBLISHED: Feb 2, 2012 1 min read

Magento Caching

Tom DiDomenico

Tom DiDomenico

Senior Vice President, Digital Strategy & Technology

Magento uses caching extensively. If you also want to be able to save something to cache rather than reading from the database or some more expense resource like that, it’s simple:

$value = Mage::app()->loadCache(‘my_cache_key’);

If the key isn’t found, $value will be null.

To store a value in the cache is almost as easy:

Mage::app()->saveCache($data_to_store, ‘my_cache_key’, array(), $duration_in_seconds);

(The empty array in the call above is standing in for a parameter called “tags” which, to my knowledge, is not used. Someone please correct me on that if I’ve got it wrong.)