Magento - Clear cache on a single category
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开发者_StackOverflow_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).
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
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 !
精彩评论