0

How should I go about creating a list of phtml files that I would like to be excluded from the standard magento caching system?

*Some Context: I have a search bar in the header of a magento site. When a search term is entered another php file is rendered through ajax with a list of relevant results. When I turn off the block cache it works perfectly but when I don't turn it off the list of results appear as normal but if you click on them they all bring you to the same product. So unless I'm missing something I assume removing this phtml file from cache will fix my problems.

2

For that you need to set the Caching lifetime of the black behind it to zero. Inchoo did an article about this I used a long while back.

Basically you need to the following to the block

protected function _construct()
{
   $this->addData(array(
      'cache_lifetime' => 3600,
      'cache_tags'     => array(Mage_Catalog_Model_Product::CACHE_TAG),
      'cache_key'      => $this->getProduct()->getId(),
   ));
}

But please, read the article, it'll help you

| improve this answer | |
  • Hi Sander, thanks very much for your answer. Would it make sense to make cache_lifetime = to zero for this purpose and if the page doesn't relate to a specific product can I leave out cache key or does it need to be replaced with something else? Thanks again :) – develophper Oct 10 '13 at 8:11
  • the cache kay you can probably leave alone, and tags too, just edit lifetime I think but I used this a long time back so maybe do some experimenting ;) – Sander Mangel Oct 10 '13 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.