Skip to content

Instantly share code, notes, and snippets.

@iods
Last active November 29, 2015 03:48
Show Gist options
  • Select an option

  • Save iods/619af0b11a18fef22955 to your computer and use it in GitHub Desktop.

Select an option

Save iods/619af0b11a18fef22955 to your computer and use it in GitHub Desktop.
Cache blocks in Magento.
<?php
/**
* Observer to core_block_abstract_to_html_before
*
* Specifies required cache information like key (block id)
* and tag (Mage_Cms_Model_Block::CACHE_TAG).
*/
public function cmsBlockCache($observer)
{
if ($block instanceof Mage_Cms_Block_Widget_Block || $block instanceof Mage_Cms_Block_Block)
{
$cacheKeyData = array(
Mage_Cms_Model_Block::CACHE_TAG,
$block->getBlockId(),
Mage::app()->getStore()->getId()
);
$block->setCacheKey(implode('_', $cacheKeyData));
$block->setCacheTags(
Mage_Cms_Model_Block::CACHE_TAG
);
$block->setCacheLifetime(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment