问题
In this Stackoverflow question the answer shows how to add a custom cache status: Magento Custom Caching with admin switch
Now my question is: Where is this triggered?
UPDATE: I've followed the steps as mentioned above. Now I have this code in Abstract/Service.php
final class COMP_NAME_Abstract_Service
{
static private $_instance;
private $_licenseHelpers = array();
public function clearCache( $custom = false )
{
//DO SOMETHING
}
public function getCache()
{
//DO SOMETHING
}
}
But I have to 'call' the clearCache function somewhere, but where and how?
回答1:
You can use event adminhtml_cache_refresh_type
.
Add to event section in global.
<global>
<events>
<adminhtml_cache_refresh_type>
<observers>
<module_alias>
<class>COMPNAME_MODULENAME_Model_Observer</class>
<type>singleton</type>
<method>cleanCacheType</method>
</module_alias>
</observers>
</adminhtml_cache_refresh_type>
</events>
</global>
Add this code to observer COMP_NAME_module_name_Model_Observer
:
public function cleanCacheType(Varien_Event_Observer $observer)
{
if ($observer->getData('type') == "your_cache_type"){
//CUSTOM CODE
}
}
回答2:
check event application_clean_cache
when clear cache like - Mage::app()->cleanCache();
or when system saves product etc...
and take a look on event - adminhtml_cache_refresh_type when clearing cache via admin panel
and your code in observer
Mage::app()->getCache()->clean('all', array('my_tag'));
and need add some logic to Observer, for check need refresh cache or not
回答3:
What do you mean by triggerd? How you write things into this new cache?
Mage::app()->saveCache($data, $cacheKey, $this->getCacheTags(), $this->getCacheLifetime());
and the cache tags are used for deletion
来源:https://stackoverflow.com/questions/15040144/magento-where-is-the-trigger-of-the-custom-cache