I would like to refresh my extension cache when Magento Collections Data Collection data files. COLLECTION_DATA cache is refreshed and also for other events, which cleans this cache.
I have a custom class, the main parts are:
$this->_usecache = Mage::app()->useCache('collections');
if ($this->_usecache){
$cache = Mage::app()->getCache();
$key = "mycategory".$this->_config['rootid'];
$this->tmpAllItems = $cache->load($key);
} else {
$this->tmpAllItems = false;
}
if ($this->tmpAllItems === false){
$this->tmpAllItems = array();
$model = Mage::getModel('catalog/category');
$categories = $model->getCategories($this->_config['rootid'], 0, true, false, true);
$k = array_keys($categories->getNodes());
$parent = $categories[$k[0]]->getParent();
$this -> treeToFlat($parent);
if ($this->_usecache)
{
$cache->save(serialize($this->tmpAllItems),
$key,
array(Mage_Catalog_Model_Category::CACHE_TAG,
Mage_Core_Model_App::CACHE_TAG)
);
} else {
$this->tmpAllItems = unserialize($this->tmpAllItems);
}
return $this->tmpAllItems;
So, my target is to refresh/clean this cache too when Mage_Catalog_Model_Category::CACHE_TAG is cleaned. How is this possible?
UPDATE #1
When I have used
$cache = Mage::app()->getCacheInstance();
instead of
$cache = Mage::app()->getCache();
The clean started to work. When I have a category, the list refreshed, but if nothing happened, it stayed cache. Also could someone explain why is this possible with this changing?
Solution
...
$cache->save(serialize($this->tmpAllItems),$key,array('my_cache_tag'));
....
Then clear:
$cache = Mage::app()->getCache(); foreach($cache->getTags() as $tag){ if(strpos($tag, 'my_cache_tag')){ $ids = $cache->getIdsMatchingAnyTags(array($tag)); foreach($ids as $id){ $cache->remove($id); } } }