您可以覆盖该块并设置一个非常低或错误的 cache_lifetime。
例如,您可以将块复制到本地命名空间。例如,如果您想禁用导航块上的缓存,您可以复制
app\code\core\Mage\Catalog\Block\Navigation.php
到
app\code\local\Mage\Catalog\Block\Navigation.php
这将覆盖 Magento 块,并允许您使用我们的更改对其进行更新。
然后您可以更改此块或大多数其他块的缓存机制以满足您的需要。下面是禁用此块缓存的示例。
protected function _construct()
{
$this->addData(array(
'cache_lifetime' => false, // or 1 or something tiny
));
}
或者,添加如下内容:
public function getCacheLifetime()
{
return null; // or 1 or what ever..
}
您还可以更改存储页面时用作唯一标识符的缓存'Key',这是模板块的默认缓存键:
/**
* Get cache key informative items
*
* @return array
*/
public function getCacheKeyInfo()
{
return array(
'BLOCK_TPL',
Mage::app()->getStore()->getCode(),
$this->getTemplateFile(),
'template' => $this->getTemplate()
);
}
数组中的每个元素都被组合在一起,以创建一个唯一的键,用于生成缓存,根据您的要求进行更改会有所帮助。
正如您在上面看到的,商店代码在那里,这意味着缓存将记录商店的店面/语言,以及每种语言/店面作为它自己的缓存页面。
根据您使用的块,您可以添加额外的参数以使缓存或多或少有针对性。