0

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.

1
  • are you talking about static blocks in the footer or all static blocks anywhere on the page? Commented Sep 9, 2016 at 20:04

2 Answers 2

0

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);
        }
    }
}
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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