8

I added this code in local.xml

<default>
    <reference name="footer">
         <action method="unsetData"><key>cache_lifetime</key></action>
         <action method="unsetData"><key>cache_tags</key></action>
    </reference>
</default>

But it didn't work. How can I refresh cache for footer.phtml programatically?

2

4 Answers 4

6

Sanjana, you can do this two ways:

Disable with getChildHtml()

According to Magento's getChildHtml() you can tell it to use the cache or not to by sending the second parameter:

public function getChildHtml($name = '', $useCache = true, $sorted = false)

Set $useCache for this block when calling $this->getChildHtml('footer'): $this->getChildHtml('footer', false) in

  • 1column.phtml
  • 2columns-left.phtml
  • 2columns-left.phtml and
  • 3columns.phtml

which are root template files.

By setting the cache lifetime to null in layout.xml and create helper

Let's use a simple helper:

class My_Module_Helper_Data extends Mage_Core_Helper_Abstract {

public function returnNull() 
{
    return null;
} 

}

And set the value in layout xml like this:

<reference name="footer">
    <action method="setCacheLifetime"><lifetime helper="mymodule/returnNull" /></action> </reference>

All thanks to Fabrizio Branca

6
  • Hi Amit.. Where i need to add this line. public function getChildHtml($name = '', $useCache = true, $sorted = false)
    – sanjana
    Apr 10, 2015 at 6:25
  • Already explained it. in root layout file 1column.phtml
    – Amit Bera
    Apr 10, 2015 at 6:30
  • These solutions didn't work for my site.
    – sanjana
    Apr 10, 2015 at 10:06
  • Is there any other solution for this.. I m stuck with this issue since last two days. thanks in advance
    – sanjana
    Apr 10, 2015 at 10:07
  • 1
    Third option - add public function getCacheLifetime() { return null; } to the footer block. This is only a good option if you already have a local override. If you don't, go with one of those other two options.
    – scrowler
    Nov 7, 2015 at 4:32
1

The issue you are facing is the same that Fabrizio explains here:

http://fbrnc.net/blog/2015/06/cache-and-layout-xml-tricks

To paraphrase his blog post, when you are setting the cache lifetime in the xml any of the values that you pass into the node <action method="setCacheLifetime"> will evaluate to true. Even if you pass null, that will be converted to a string, and that string will be true. What you have to do is create a helper class that can set the value of null in the node.

Create a blank module and add your config file:

{{site_root}}/app/code/local/{{your_namespace}}/CacheNull/ect/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <{{your_namespace}}_CacheNull>
            <version>1.0.0</version>
        </{{your_namespace}}_CacheNull>
    </modules>
    <global>
        <helpers>
            <customcachenull>
                <class>{{your_namespace}}_CacheNull_Helper</class>
            </customcachenull>
        </helpers>
    </global>
</config>

Then create your helper class:

{{site_root}}/app/code/local/{{your_namespace}}/CacheNull/Helper/Data.php

class {{your_namespace}}_CacheNull_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function returnNull()
    {
        return null;
    } 
}

Once you verify that the module is loading correctly on your site, you can add in the needed xml to remove the footer from the cache:

{{site_root}}/app/design/frontend/{{you_theme_namespace}}/{{your_theme}}/layout/local.xml

<reference name="footer">
    <action method="setCacheLifetime"><lifetime helper="customcachenull/returnNull" /></action>
</reference>

To check if the footer is in fact not being cached, take another tool from Fabrizio:

https://github.com/AOEpeople/Aoe_TemplateHints

Using this you will be able to see in full color what blocks are being cached as well as a bunch of other useful info about your site's content.

0

The last step may need to be modified:

<reference name="footer">
    <action method="setCacheLifetime"></action>
</reference>
0

Working

  • set null via helper

    <reference name="footer">
        <action method="setCacheLifetime">
            <value helper="helper/method" />
        </action>
    </reference>
    
  • pass no argument

    <reference name="footer">
        <action method="setCacheLifetime"></action>
    </reference>
    
  • use JSON data

    <action method="setCacheLifetime" json="value">
        <value>null</value>
    </action>
    

Not working:

  • set null as string

    <reference name="footer">
        <action method="setCacheLifetime">
            <value>null</value>
        </action>
    </reference>
    
  • empty value

    <reference name="footer">
        <action method="setCacheLifetime">
            <value></value>
        </action>
    </reference>
    

Source: http://fbrnc.net/blog/2015/06/cache-and-layout-xml-tricks

Your Answer

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

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