Magento 不缓存警报

发布于 2024-12-14 19:57:11 字数 2899 浏览 1 评论 0原文

我已在我的 Magento 商店中安装了此扩展: http://www.magentocommerce.com/ magento-connect/catalogcache.html

它确实缩短了目录列表的页面加载时间。问题是警报不再显示。例如,如果有人订阅在产品重新有货时收到通知,则页面重新加载时会出现“警报已成功添加”消息。

有谁知道如何防止缓存警报?

这是扩展程序的代码:

    class Netresearch_CatalogCache_Block_Product_View extends Mage_Catalog_Block_Product_View
/**
 * replace this parent class by your inhereted version of th Product_View Block
 * e.g. class Netresearch_CatalogCache_Block_Product extends MyNameSpace_MyModule_Catalog_Block_Product_View
 */
{
    protected function _isCacheActive()
    {
        if(!Mage::getStoreConfig('catalog/frontend/cache_view')) {
            return false;
        }

        /* if there are any messages dont read from cache to show them */
        if(Mage::getSingleton('core/session')->getMessages(true)->count() > 0) {
            return false;
        }


        return true;
    }

    public function getCacheLifetime()
    {
        if($this->_isCacheActive())
        {
            return false;
        }
    }
/*
    protected function _loadCache()
    {
        $cache = parent::_loadCache();
        Mage::debug($cache===false? "computed":"from cache");
        return $cache;
    }
*/
    public function getCacheKey()
    {
        if(!$this->_isCacheActive()) {
            parent::getCacheKey();
        }
        $_taxCalculator = Mage::getModel('tax/calculation');
        $_customer = Mage::getSingleton('customer/session')->getCustomer();
        $_product = $this->getProduct();
        return 'ProductView'.
            /* Create differnet caches for ...
             * ... for different products */
            $_product->getId().'_'.
            /* ... for different stores */
            Mage::App()->getStore()->getCode().'_'.
            /* ... for different customer groups */
            $_customer->getGroupId().'_'.
      /* ADD CURRENCY CODE TO ID */
      Mage::app()->getStore()->getCurrentCurrencyCode().'_'.
            /* ... for different tax classes (related to customer and product) */
            $_taxCalculator->getRate(
                $_taxCalculator
                    ->getRateRequest()
                    ->setProductClassId($_product->getTaxClassId()
                )
            ).'_'.
            '';
    }


    public function getCacheTags()
    {
        if(!$this->_isCacheActive()) {
            return parent::getCacheTags();
        }
        return array(
            Mage_Catalog_Model_Product::CACHE_TAG,
            Mage_Catalog_Model_Product::CACHE_TAG."_".$this->getProduct()->getId()
        );

    }
}

我在这里问了一个关于商店货币的类似问题并得到了解决方案: Magento - 不缓存货币

I had installed this extension on my Magento store: http://www.magentocommerce.com/magento-connect/catalogcache.html

It really improved the page load time for the catalog listings. The problem is alerts no longer show up. For example if someone subscribes to get notified when a product is back in stock the "Alert successfully added" message appear on page reload..

Does anyone know how I can prevent the alerts from caching?

Here is the code from the extension:

    class Netresearch_CatalogCache_Block_Product_View extends Mage_Catalog_Block_Product_View
/**
 * replace this parent class by your inhereted version of th Product_View Block
 * e.g. class Netresearch_CatalogCache_Block_Product extends MyNameSpace_MyModule_Catalog_Block_Product_View
 */
{
    protected function _isCacheActive()
    {
        if(!Mage::getStoreConfig('catalog/frontend/cache_view')) {
            return false;
        }

        /* if there are any messages dont read from cache to show them */
        if(Mage::getSingleton('core/session')->getMessages(true)->count() > 0) {
            return false;
        }


        return true;
    }

    public function getCacheLifetime()
    {
        if($this->_isCacheActive())
        {
            return false;
        }
    }
/*
    protected function _loadCache()
    {
        $cache = parent::_loadCache();
        Mage::debug($cache===false? "computed":"from cache");
        return $cache;
    }
*/
    public function getCacheKey()
    {
        if(!$this->_isCacheActive()) {
            parent::getCacheKey();
        }
        $_taxCalculator = Mage::getModel('tax/calculation');
        $_customer = Mage::getSingleton('customer/session')->getCustomer();
        $_product = $this->getProduct();
        return 'ProductView'.
            /* Create differnet caches for ...
             * ... for different products */
            $_product->getId().'_'.
            /* ... for different stores */
            Mage::App()->getStore()->getCode().'_'.
            /* ... for different customer groups */
            $_customer->getGroupId().'_'.
      /* ADD CURRENCY CODE TO ID */
      Mage::app()->getStore()->getCurrentCurrencyCode().'_'.
            /* ... for different tax classes (related to customer and product) */
            $_taxCalculator->getRate(
                $_taxCalculator
                    ->getRateRequest()
                    ->setProductClassId($_product->getTaxClassId()
                )
            ).'_'.
            '';
    }


    public function getCacheTags()
    {
        if(!$this->_isCacheActive()) {
            return parent::getCacheTags();
        }
        return array(
            Mage_Catalog_Model_Product::CACHE_TAG,
            Mage_Catalog_Model_Product::CACHE_TAG."_".$this->getProduct()->getId()
        );

    }
}

I asked a similar question here about the store currency and got the solution:
Magento - Don't Cache Currency

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ヤ经典坏疍 2024-12-21 19:57:11

我不使用这个模块,但一直致力于 Magento 的缓存,并使用下面的代码来避免系统消息缓存。这可能对你有用?然后您可以尝试:

protected function _isCacheActive()
{
    if(!Mage::getStoreConfig('catalog/frontend/cache_view')) {
        return false;
    }

    /* if there are any messages dont read from cache to show them */
    if($this->getMessagesBlock()->getGroupedHtml()) {
        return false;
    }


    return true;
}

I don't use this module but have worked on caching for Magento and used the code below to avoid system messages caching. This may work for you ? You may then try :

protected function _isCacheActive()
{
    if(!Mage::getStoreConfig('catalog/frontend/cache_view')) {
        return false;
    }

    /* if there are any messages dont read from cache to show them */
    if($this->getMessagesBlock()->getGroupedHtml()) {
        return false;
    }


    return true;
}
兲鉂ぱ嘚淚 2024-12-21 19:57:11

似乎正在检查 Mage::getSingleton('core/session') 是否有可显示的消息,很可能新闻通讯模块将消息写入 Mage::getSingleton('customer/session') code> 所以也需要检查

Seems it's checking Mage::getSingleton('core/session') for available messages to display, most likely newsletter module writes messages to Mage::getSingleton('customer/session') so it needs te be checked as well

行雁书 2024-12-21 19:57:11

实际上,只要有人添加到购物车,我的缓存就会被刷新。经过进一步调查,我发现“Mage_Core_Block_Template”具有默认的 CACHE_GROUP = 'block_html',它是 Mage_Core_Block_Product_view 的父类。因此,在创建任何购物车时,block_html 都会从 magento 中清除,但这并不能解决问题。

我的理解是正确的还是我遗漏了什么?

Actually, as soon as any person adds to the cart, my cache is flushing out. On further investigation, I found out that "Mage_Core_Block_Template" has default CACHE_GROUP = 'block_html' which is the parent class for the Mage_Core_Block_Product_view. Hence on create of any cart, the block_html is flushed out from the magento and this does not solve the problem.

Am I correct in the understanding or am I missing something?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文