I suspect that because I'm re-using the block dynamically that it will always have the same block id and therefore the fix will not work
That's right. And by adding dynamic content to a static block you are using it not as it is intended. You should use layout XML to add dynamic blocks with more flexibility.
If you insist on adding the content by selecting a static block in the category, you will need one static block for each category which then includes the dynamic template with different parameters. Which brings us to the next problem:
the CMS Static Block contains {{block type="core/template" template="template/category-block.phtml"}} which calls the custom phtml file.
This one is cached as well.
The inserted block is not a CMS block (cms/block
) but a regular template block (core/template
) so it does not even have a block id. But the problem stays: the cache key is the same for both instances.
This is how the cache key is generated for core/template
blocks:
public function getCacheKeyInfo()
{
return array(
'BLOCK_TPL',
Mage::app()->getStore()->getCode(),
$this->getTemplateFile(),
'template' => $this->getTemplate()
);
}
See Mage_Core_Block_Template
The actual cache key is a sha1 hash of all array values joined with "|". But you also can manually specify any unique string as cache key, for example:
{{block type="core/template"
template="template/category-block.phtml"
cache_key="CATEGORY_BLOCK_DEFAULT_STORE_CATEGORY_42"}}
Best Answer
I had this problem with EE 1.14.2 and it looks like the same issue has come up in CE 1.9.2. I documented my problem and solution on this SE question.
Basically due to the following code being added to the constructor of
Mage_Cms_Block_Block
:CMS static blocks are now cached. The problem arises from how the cache key info is generated. It falls back to the
Mage_Core_Block_Abstract
behavior of using the blocks name in layout. If the block hasn't been added with layout, e.g on a cms page, this name doesn't exist. This can result in static blocks sharing the same cache key and getting mixed up in cache.My solution was to override the
Mage_Cms_Block_Block
class and set the cache key info based on the block id and current store.Obviously this would need to be added in your own module with a
config.xml
file and block override etc. Alternatively you could copyMage_Cms_Block_Block
to the local code pool and add the cache key there.You can see the new lines added in 1.9.2 here