Block Caching

Updated . Posted . Visible to the public.

To cache a block individually, add this method to the blocks class:

protected function _construct()
{
    $this->addData(array(
        'cache_lifetime' => 3600,
        'cache_tags'     => array(Mage_Cms_Model_Block::CACHE_TAG),
        'cache_key'      => 'CACHE_KEY',
    ));
}

Note - if you set cache_lifetime to 0 (or any other value which PHP evaluates to false) then the cache will actually last 7200 seconds (2 hours), so in order to have a very high cache time then the cache_lifetime should be set to anything up to 9999999999 (about 317 years)

Show archive.org snapshot

Profile picture of Mike Whitby
Mike Whitby
Last edit
Posted by Mike Whitby to Magento (2012-04-23 10:34)