i have requirement that i want to disable caching for some category on product listing page and on product view page.
i have search for this but i have not found any relevant answer,is this possible to do in the magento?
I have try in list.phtml and view.phtml file
-
Do you mean entire pages, or just certain parts of pages? Such as the `list.phtml` part of the category page? – Alex Hadley May 08 '12 at 13:39
-
try here http://stackoverflow.com/questions/8405232/disable-bypass-magento-full-page-cache-on-single-page – Alex Hadley May 08 '12 at 13:42
-
No i want to cache only list.phtml file, and this link not working for me – May 08 '12 at 13:50
-
The question I linked to talks about whole page and block level caching. Try http://oggettoweb.com/blog/customizations-compatible-magento-full-page-cache/ which that question links to. – Alex Hadley May 08 '12 at 13:58
1 Answers
You can override the block and set a really low or false cache_lifetime.
For example you can copy the block to the local namespace. For example if you wanted to disable caching on the navigation block you could copy
app\code\core\Mage\Catalog\Block\Navigation.php
to
app\code\local\Mage\Catalog\Block\Navigation.php
This will override the Magento block, and allow you update it with our changes.
You could then change the caching mechanism for this block, or most other blocks to suit your needs. Below is an example of disabling the cache for this block.
protected function _construct()
{
$this->addData(array(
'cache_lifetime' => false, // or 1 or something tiny
));
}
Alternatively, add something like this:
public function getCacheLifetime()
{
return null; // or 1 or what ever..
}
You can also change the cache 'Key' used as a unique identifier when storing the page, this is the default cache key for template blocks:
/**
* Get cache key informative items
*
* @return array
*/
public function getCacheKeyInfo()
{
return array(
'BLOCK_TPL',
Mage::app()->getStore()->getCode(),
$this->getTemplateFile(),
'template' => $this->getTemplate()
);
}
Each element in the array is combined to create a unique key used when generating the cache, changing this can help depending on your requirements. As you can see above the store code is in there, which means the cache will take note of the store front/language of the store, and each language/store front as it's own cached page.
Depending on the block you are using you could add in extra parameters to make the cache more or less targeted.

- 12,617
- 1
- 34
- 48
-
-
Thanks Andrew,I am facing problems in my navigation because of "Blocks HTML output" cache.I am using Magento Enterprise edition.You can see my issue on this link "http://www.magentocommerce.com/boards/viewthread/298493/" – Mukesh Nov 23 '12 at 10:28
-
-
`'cache_lifetime' => false` will actually put the cache lifetime back to 7200 seconds! – Seth Malaki Feb 15 '13 at 15:43