I don't want footer content and static blocks to get cached due to presence of some dynamic content in it. How Can I do it from code.
2 Answers
You can add an observer on this event: core_block_abstract_to_html_before
<global> ... <events> <core_block_abstract_to_html_before> <observers> <your_observer_key> <class>yourmodule/observer</class> <method>cleanFooterCache</method> </your_observer_key> </observers> </core_block_abstract_to_html_before> </events> ... </global>
Then in your observer method:
public function cleanFooterCache(Varien_Event_Observer $observer) { if (!Mage::app()->getStore()->isAdmin()) { $block = $observer->getEvent()->getBlock(); if ($block instanceof Mage_Page_Block_Html_Footer || $block instanceof Mage_Cms_Block_Block) { //Get the cache instance, because Mage::app()->cleanCache($tags=array()); cleans by any matching tag. $cacheModel = Mage::app()->getCacheInstance(); $mode = Zend_Cache::CLEANING_MODE_MATCHING_TAG; $cacheTags = $block->getCacheTags(); //This method is available in Mage_Core_Block_Abstract //Copy the methods _tags() and _id() functionality from Mage_Core_Model_Cache foreach ($cacheTags as $key => $value) { $cacheTags[$key] = $value? strtoupper($value) : $value; } //Clean the cache for the given tags. $cacheModel->getFrontend()->clean($mode, $cacheTags); } } }
Write Below code in your local.xml or any other your custom layout file and your footer will not be cache
<reference name="footer">
<action method="setCacheLifetime"><lifetime>null</lifetime></action>
</reference>