Magento: where is the trigger of the custom cache?

陌路散爱 提交于 2020-01-24 19:34:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!