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.

  • are you talking about static blocks in the footer or all static blocks anywhere on the page? – Fabian Schmengler Sep 9 '16 at 20:04

You can add an observer on this event: core_block_abstract_to_html_before


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);
| improve this answer | |

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>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.