1

unfortunately in this situation I do not have $this->getChildHtml to assign false to it and then change my xml file for disabling cache I have this block in view.phtml:

    <?php echo $this->getCmsBlockHtml() ?>

and the function is in view.php as follow:

public function getCmsBlockHtml()
{
    if (!$this->getData('cms_block_html')) {
        $html = $this->getLayout()->createBlock('cms/block')
            ->setBlockId($this->getCurrentCategory()->getLandingPage())
            ->toHtml();
        $this->setData('cms_block_html', $html);
    }
    return $this->getData('cms_block_html');
}

any ideas on how to disable the cache here? my page is in category folder when displaying the products

Update:with help of Denis I understood that (for some pages) when I have something in constructor if the cache is enabled the constructor will not be called! and so I think that's the reason why setting the cache life time doesn't work there

2

To disable Block Html Cache you should set cacheLifeTime to null. You can see more details in Mage_Core_Block_Abstract::_loadCache()

protected function _loadCache()
{
    if (is_null($this->getCacheLifetime()) || !$this->_getApp()->useCache(self::CACHE_GROUP)) {
        return false;
    }
    ...
}
1

In Mage_*_Block_Template classes you can control the cache through the constructor

protected function _construct()
{
    $this->addData(array(
                    'cache_lifetime'   => 86400, //1 day
                    'cache_tags'   => array(Mage_Catalog_Model_Product::CACHE_TAG), //for adding in product detail page
                    'cache_key'   => 'some-identifier' //optional, but should be unique if used
    ));
}

In definition createBlock function, we have three parameters:

public function createBlock ($type, $name = '', $attributes = array()) 

You can then use the parameters to pass attributes of the data cache, like this:

$html = $this->getLayout()->createBlock('cms/block','',
    array(
        'cache_lifetime' => false,
        'cache_tags' => array(Mage_Catalog_Model_Product::CACHE_TAG)
    ))
    ->setBlockId($this->getCurrentCategory()->getLandingPage())
    ->toHtml();
4
  • I added the constructor in view.php and then I added the block attributes just like you said but unfortunately I am not seeing any difference
    – Nickool
    Aug 11 '14 at 16:48
  • Try use 1 in 'cache_lifetime' value (1 ms for lifetime). I'll test it soon. Aug 11 '14 at 19:49
  • as I updated the question the problem is that the constructor only performs when cache is disabled
    – Nickool
    Aug 11 '14 at 20:12
  • It's not work for me Apr 13 '17 at 8:43

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.