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?

sv3n
  • 11,657
  • 7
  • 40
  • 73
sanjana
  • 81
  • 1
  • 2

4 Answers4

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

Amit Bera
  • 77,456
  • 20
  • 123
  • 237
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.

sv3n
  • 11,657
  • 7
  • 40
  • 73
circlesix
  • 4,273
  • 3
  • 27
  • 57
0

The last step may need to be modified:

<reference name="footer">
    <action method="setCacheLifetime"></action>
</reference>
Niels
  • 1,406
  • 13
  • 24
kenny
  • 1
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

sv3n
  • 11,657
  • 7
  • 40
  • 73