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
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 :