Я установил это расширение в своем магазине 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 - не кешировать валюту