无法阻止Magento缓存块

Exc*_*bur 6 magento

我正在使用Magento 1.6站点,该站点在主页的CMS"布局更新XML"字段中包含以下xml:

<reference name="content">
   <block type="catalog/navigation" name="catalog.category.home" as="homecategory" template="catalog/category/homecategory.phtml" />
</reference>
Run Code Online (Sandbox Code Playgroud)

由于模板显示随机类别,我想禁用此块的缓存.为此,我尝试使用getChildHtml('sub-block-template',false)以及以下内容:

(homecategory 在其模板中有$ this-> getChildHtml('random_categories',false))

<reference name="content">
    <block type="catalog/navigation" name="catalog.category.home" as="homecategory" useCache="false" template="catalog/category/homecategory.phtml">
        <block type="catalog/navigation" name="catalog.category.home.randcats" as="random_categories"  useCache="false" template="catalog/category/random.phtml" />
    </block>
</reference>
Run Code Online (Sandbox Code Playgroud)

所以现在我陷入困境,想知道为什么我不能阻止缓存该块,尽管使用'false'参数.

小智 6

我有同样的问题.我相信它必须使用type ="catalog/navigation"的块类型做一些事情.我已经看到这种禁用缓存工作在其他类型的块上.以下是此块类型的修复和此问题:

phtml文件更改:确保第二个参数为false

echo $this->getChildHtml('topCategoriesList',false);
Run Code Online (Sandbox Code Playgroud)

xml文件更改: 将这些操作添加到块中

<block type="catalog/navigation" name="topCategoriesList" as="topCategoriesList"    template="catalog/navigation/categorylist.phtml">
   <action method="unsetData"><key>cache_lifetime</key></action>
   <action method="unsetData"><key>cache_tags</key></action>
</block>
Run Code Online (Sandbox Code Playgroud)


Jon*_*ona 3

您是否尝试过通过创建新的自定义块类型并重载缓存功能来强制执行它?扩展 Mage_Catalog_Block_Product_List_Random 类并创建一个空的伪构造函数:

protected function _construct() {}
Run Code Online (Sandbox Code Playgroud)

这将防止继承添加缓存标签、生命周期和其他元数据到块对象。然后,您也可以重载缓存键信息,以便它不使用任何现有的(或启用的)缓存块。例如:

public function getCacheKeyInfo()
{
    return array(
        'MY_CACHE_TAG',
        Mage::app()->getStore()->getId(),
        (int)Mage::app()->getStore()->isCurrentlySecure(),
        Mage::getDesign()->getPackageName(),
        Mage::getDesign()->getTheme('template')
    );
}
Run Code Online (Sandbox Code Playgroud)