【问题标题】:Hole Punching in Magento not WorkingMagento中的打孔不起作用
【发布时间】:2014-08-06 11:03:26
【问题描述】:

我为目录/产品价格块尝试了这个,但我得到了:

致命错误:在 /var/www/html/app/code/core/Mage/Catalog/Block/Product/Price.php 中的非对象上调用成员函数 getCacheIdTags()在第 176 行

有什么想法吗?

<?xml version="1.0" encoding="UTF-8"?>
<config>
 <placeholders>
  <catalog_product_price>
    <block>catalog/product_price</block>
    <placeholder>TEST_CACHE</placeholder>
    <container>Test_PageCache_Model_Container_Cache</container>
    <cache_lifetime>0</cache_lifetime>
  </catalog_product_price>
 </placeholders>
</config>

还有我的容器

class Test_PageCache_Model_Container_Cache extends Enterprise_PageCache_Model_Container_Abstract{

   protected function _getCacheId()
   {
       return 'TEST_CACHE' . md5($this->_placeholder->getAttribute('cache_id'));
   }

   protected function _renderBlock()
   {
       $blockClass = $this->_placeholder->getAttribute('block');
       $template = $this->_placeholder->getAttribute('template');

       $block = new $blockClass;
       $block->setTemplate($template);

       return $block->toHtml();
   }

   protected function _saveCache($data, $id, $tags = array(), $lifetime = null) { return false; }}

我启用了 FPC 来检查这个,但是当我刷新块所在的页面时,我得到了后面提到的错误。

谢谢

【问题讨论】:

    标签: magento caching hole-punching


    【解决方案1】:

    这样做解决了:

    public function getCacheKeyInfo() {
        $data = parent::getCacheKeyInfo();
    
        if(Mage::registry('current_product'))
        {
            **$data['product'] = Mage::registry('current_product')->getId();** //can be a product id, etc.
        }
        return $data;
    }
    

    然后在我的缓存容器中:

     protected function _renderBlock()
    {
        try
        {
            $blockClass = $this->_placeholder->getAttribute('block');
            $template = $this->_placeholder->getAttribute('template');
    
    
            $block = new $blockClass;
            $block->setTemplate($template);
            **$block->setProductId($this->_placeholder->getAttribute('product'));**
    
            return $block->toHtml();
        }
        catch(Exception $ex)
        {
            Mage::log($ex->getMessage(), null, "system2.log");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-11
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多