6

I'm working on a Magento 1.6 site, which has the following xml inside the home page's CMS "Layout Update XML" field:

<reference name="content">
   <block type="catalog/navigation" name="catalog.category.home" as="homecategory" template="catalog/category/homecategory.phtml" />
</reference>

As the template shows randomized categories, I would like to disable caching for this block. To do so, I attempted using getChildHtml('sub-block-template', false) with the following:

(homecategory has $this->getChildHtml('random_categories', false) in its template)

<reference name="content">
    <block type="catalog/navigation" name="catalog.category.home" as="homecategory" useCache="false" template="catalog/category/homecategory.phtml">
        <block type="catalog/navigation" name="catalog.category.home.randcats" as="random_categories"  useCache="false" template="catalog/category/random.phtml" />
    </block>
</reference>

So now I'm stuck, wondering why I can't prevent caching of that block, despite using the 'false' argument.

Excalibur
  • 3,258
  • 2
  • 24
  • 32
  • There's no such thing as the 'useCache="false"' attribute. – Alana Storm Feb 05 '12 at 21:39
  • Did you disable Magento cache in Admin Panel > System > Cache Management? – sondoha Feb 05 '12 at 08:52
  • You should implement full page cache hole punching for your block. See this tutorial [this tutorial](http://tweetorials.tumblr.com/post/10160075026/ee-full-page-cache-hole-punching) and [this question on SO](http://stackoverflow.com/questions/8126548/trying-get-dynamic-content-hole-punched-through-magentos-full-page-cache). – Dmytro Zavalkin Feb 05 '12 at 21:30
  • Yeah, that was a desperate attempt on my part. Forgot to remove it from the code sample I pasted. – Excalibur Feb 07 '12 at 23:10
  • @Detzee: I need caching on this site - that's the whole point. However I wanted to have this block non-cached. I ended up going with the default 2-hour cache expiration which was an acceptable solution for this site's rotating categories on the homepage. – Excalibur Feb 07 '12 at 23:11

2 Answers2

6

I had this same problem. I beleive it has to do something with the block type of type="catalog/navigation". I've seen this disabling of caching work on other types of blocks. Here is a fix for this block type and this problem:

phtml file change: make sure the second param is false

echo $this->getChildHtml('topCategoriesList',false);

xml file change: Add these actions to the block

<block type="catalog/navigation" name="topCategoriesList" as="topCategoriesList"    template="catalog/navigation/categorylist.phtml">
   <action method="unsetData"><key>cache_lifetime</key></action>
   <action method="unsetData"><key>cache_tags</key></action>
</block>
uffa
  • 501
  • 5
  • 5
3

Have you tried forcing it by creating a new custom block type and overloading the caching functions? Extend the Mage_Catalog_Block_Product_List_Random class and create an empty pseudo-constructor:

protected function _construct() {}

This will prevent inheriting adding cache tags, lifetime, and other metadata to the block object. Then you can overload the cache key info as well so that it doesn't use any existing (or enabled) cache blocks. For example:

public function getCacheKeyInfo()
{
    return array(
        'MY_CACHE_TAG',
        Mage::app()->getStore()->getId(),
        (int)Mage::app()->getStore()->isCurrentlySecure(),
        Mage::getDesign()->getPackageName(),
        Mage::getDesign()->getTheme('template')
    );
}
Jona
  • 359
  • 3
  • 10
  • Thank you, I'll try that. Although I'm still drinking from the firehose, so creating this custom block might take some trial-and-error. – Excalibur Feb 06 '12 at 03:00
  • 1
    Maybe try looking at http://inchoo.net/ecommerce/magento/magento-block-caching/ and see if that helps you along the way? – Jona Feb 06 '12 at 04:10
  • 1
    Jona, thank you for the link to that article. I noticed where it indicated that when `$this->addData(array('cache_lifetime' => 'false'))` is the case (which is the default for Category/Navigation, this means that the cache refreshes automatically every 2 hours (7200 seconds). This is good enough for my requirements, and is probably better than no caching for performance reasons. – Excalibur Feb 06 '12 at 19:18