繁体   English   中英

无法阻止Magento缓存块

[英]Unable to prevent Magento from Caching a Block

我正在使用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>

由于模板显示随机类别,我想禁用此块的缓存。 为此,我尝试使用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>

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

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

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

echo $this->getChildHtml('topCategoriesList',false);

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>

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

protected function _construct() {}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM