By default, Magento CMS Block will not be cached. So it would be nice if we cache CMS static blocks. This is what this extension does (one of my free extension). Feel free to use it.
Basically this extension listens to the event core_block_abstract_to_html_before
and enable cacheing for CMS Blocks. This is what observer does
public function enableCmsBlockCaching(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
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(),
intval(Mage::app()->getStore()->isCurrentlySecure())
);
$block->setCacheKey(implode('_', $cacheKeyData));
$block->setCacheTags(array(
Mage_Core_Model_Store::CACHE_TAG,
Mage_Cms_Model_Block::CACHE_TAG,
(string)$block->getBlockId()
));
$block->setCacheLifetime(false);
}
return $this;
}
What this Observer Does : It first retrieve each static blocks from the layout and then apply cache. The unique cache key
is generated for each static blocks. This unique key is made up of
- CMS cache tag
- Static Block Identifier
- Current Store Used
- Secure Url or Not
So the cache key
will be unique in most of the circumstances and you already saw that for secure and not secure urls, cache key will be different. That's it.
Note : As @AdershKatri pointed out, you should also have look on this thread
If you have any doubts, let me know.