In my project we are using Magento Enterprise Edition 1.14.1. The prices in store are changed dynamically direct from Database. So the problem is Magento cache every thing (
You can see this link cache disable follwing method is added in this file Mage/Catalog/Block/Product/Price.php
protected function _construct()
{
$this->addData(
array('cache_lifetime' => false,)
);
}
Besides this being a question for the Magento Stack Exchange, you could also try
<reference name="footer">
<action method="setCacheLifetime"></action>
</reference>
Which leaves the setCacheLifetime
empty. According to your question, you didn't check that on out. Found the solution on fbrnc.net. The author there says that
This works because conveniently Varien_Object->__call() takes care of missing arguments and replaces them with
null
which again luckily is exactly what we need here
Magento 1.9.2.1
My solution was to add:
<action method="unsetData"><key>cache_lifetime</key></action>
<action method="unsetData"><key>cache_tags</key></action>
After deep digging in magento caching techniques I came across one decision. Before that I want describe that what I got. There is basically 2 solutions to disable cache for particular block or caching tags.
1. Disable cache using Block
It is something like set lifetime of cache
<reference name="needed block">
<action method="setCacheLifetime"><s>null</s></action>
</reference>
But in our case magento doesn’t have specific block for rendering the price of the product. The price template is directly defined in abstract class,
Mage_Catalog_Block_Product_Abstract
protected $_priceBlockDefaultTemplate = 'catalog/product/price.phtml';
And also this type cache will clear only the Block cache. So we can’t use this solution.
2. Hole punching : Magento having another default functionality which is we can override the FPC process using cache tags.
Magento saving caches by tag names. So that we can get that tags before the page rendering and we can disable to cache that tag again. So every time when the page loads that tag will not be cached.
I was trying to implement this using observer (core_block_abstract_to_html_before)
,
public function disableCache(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
if ($block instanceof Mage_Catalog_Block_Product_Price) {
//echo 'got it'; exit;
$cacheKeyData = array(
Mage_Catalog_Block_Product_Price::CACHE_TAG,
$block->getBlockId(),
Mage::app()->getStore()->getId(),
intval(Mage::app()->getStore()->isCurrentlySecure())
);
}
}
But there is no CACHE_TAG
for price (not defined for price).
And we can set the life time of cache directly in price class using __construct()
function, like
$this->addData(array(
‘cache_lifetime’=> false,
‘cache_tags’ => array(Mage_Core_Model_Store::CACHE_TAG, Mage_Catalog_Product_Price::CACHE_TAG)
));
As like above I mentioned, there is no CACHE_TAG
for price. So we can’t use this trick also.
But I found one thing that if we save the product from admin then immediately the changes is reflecting in front end. So I dig more in that and I found the solution.
Magento calls the following control action,
Mage_Adminhtml_Catalog_ProductController::saveAction()
and this one will call the following method,
Mage::getModel('catalogrule/rule')->applyAllRulesToProduct($productId)
If you see this function they clear cache and re-indexing.
public function applyAllRulesToProduct($product)
{
.......
$this->getResource()->applyAllRules($product);
$this->_invalidateCache();
Mage::getSingleton('index/indexer')->processEntityAction(
new Varien_Object(array('id' => $product->getId())),
Mage_Catalog_Model_Product::ENTITY,
Mage_Catalog_Model_Product_Indexer_Price::EVENT_TYPE_REINDEX_PRICE
);
return $this;
}
So in my case I just using the following code.
$object->setPrice(555);
Mage::getModel('catalogrule/rule')->applyAllRulesToProduct($productId);
$object->save();
Try
<action method="setCacheLifetime"><value>false</value></action>
HTH