Magento: where is the trigger of the custom cache?

2019-07-17 02:42发布

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?

3条回答
孤傲高冷的网名
2楼-- · 2019-07-17 03:19

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
   }
}
查看更多
Bombasti
3楼-- · 2019-07-17 03:19

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

查看更多
成全新的幸福
4楼-- · 2019-07-17 03:25

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

查看更多
登录 后发表回答