#magento #caching #hole-punching
#magento #кэширование #пробивка отверстий
Вопрос:
Я пробовал это для блока catalog / product_price, но я получаю:
Неустранимая ошибка: вызов функции-члена getCacheIdTags() для не-объекта в /var/www/html/app/code/core/Mage/Catalog/Block/Product/Price.php в строке 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, чтобы проверить это, но когда я обновляю страницу, на которой находится блок, я получаю сообщение об ошибке, упомянутое позже.
Спасибо
Ответ №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");
}
}