无法阻止Magento缓存块 [英] Unable to prevent Magento from Caching a Block

查看:67
本文介绍了无法阻止Magento缓存块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Magento 1.6网站上工作,该网站的主页CMS布局更新XML"字段中包含以下xml:

I'm working on a Magento 1.6 site, which has the following xml inside the home page's CMS "Layout Update XML" field:

<reference name="content">
   <block type="catalog/navigation" name="catalog.category.home" as="homecategory" template="catalog/category/homecategory.phtml" />
</reference>

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

As the template shows randomized categories, I would like to disable caching for this block. To do so, I attempted using getChildHtml('sub-block-template', false) with the following:

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

(homecategory has $this->getChildHtml('random_categories', false) in its template)

<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'参数也无法阻止对该块进行缓存.

So now I'm stuck, wondering why I can't prevent caching of that block, despite using the 'false' argument.

推荐答案

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

Have you tried forcing it by creating a new custom block type and overloading the caching functions? Extend the Mage_Catalog_Block_Product_List_Random class and create an empty pseudo-constructor:

protected function _construct() {}

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

This will prevent inheriting adding cache tags, lifetime, and other metadata to the block object. Then you can overload the cache key info as well so that it doesn't use any existing (or enabled) cache blocks. For example:

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

这篇关于无法阻止Magento缓存块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆