2

How can I clear the cache on a single category? When FPC (Full page cache) is turned on, display out of stock items is turned off, and a product is sold out, the category page still shows the product (with no "out of stock" message). When the user clicks on to the page, the product is still listed as in-stock. I've added an observer to clear cache on the product and that has resolved the product page. However, I can't seem to clear the cache for the category pages. Here is what I've tried so far:

I tried this based on what was in the Mage_Catalog_Model_Category::move method:

Mage::app()->cleanCache(array(Mage_Catalog_Model_Category::CACHE_TAG));

but that looks like it should clear the cache of all categories (Doesn't seem to work when I use it). I want something that would allow me to clear the cache of category_id=123.

I also tried:

Mage::app()->cleanCache('catalog_category'.$category_id);

but that didn't seem to do anything at all either (NOTE 'catelog_category' is the value of Mage_Catalog_Model_Category::CACHE_TAG).

2 Answers 2

1

So it looks like to clear the FPC you have to use:

Mage::app()->getCacheInstance()->cleanType('full_page');

but this refreshes all of the FPC. My final solution required me to clear FPC and reindex the category using:

Mage::getSingleton('index/indexer')->processEntityAction(
    $category, Mage_Catalog_Model_Category::ENTITY, 
        Mage_Index_Model_Event::TYPE_SAVE
);

where $category is a Mage_Catalog_Model_Category instance

2
  • While this was the ultimate "fix". I would still like to be able to clear the FPC for a single category rather than clearing all of the FPC. Commented Sep 20, 2011 at 19:00
  • Did you find any solution for this?. I'm also looking same one. I need to clear cache for particular products from FPC. If you come across any solution please help me. Thanks.
    – Elavarasan
    Commented Jan 8, 2015 at 3:34
1

The tags need to be precise:

Mage::app()->cleanCache(array(Mage_Catalog_Model_Category::CACHE_TAG.'_1234'));

You can look it up in your cache system or use filesystem caching and openup the meta files in /var/cache/.

Good luck and happy hacking !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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