Magento – create and call own cache key for block

blockscachekey

Our headers caching over one another. A solution that i've come up with involves creating and calling these separate cached pages from a non-cached environment. Seems like it'd be a successful endeavor. What is the best way to acomplish this goal?

Is it possible to create a cache key for a block?

Best Answer

Yes you can cache each of the block in accordance with your need. There are lot of tutorials regarding about this topic. Some of the Best resources available are listing below.

Basically in your block's __construct, you need to setup block cache somewhat liket this.

class {NS}_{Module}_Block_{View} extends Mage_Core_Block_Template 
{

    protected function _construct()
    {
        $this->addData(array(
            'cache_lifetime'    => 120,
            'cache_tags'        => array(Mage_Catalog_Model_Product::CACHE_TAG),
            'cache_key'         => $this->getProduct()->getId(),
        ));
    }   

}