Magento refresh cache on plugin save

两盒软妹~` 提交于 2019-12-22 14:47:14

问题


I have written a simple Magento plugin that simply lists all sub categories that are enabled from a given parent id.

The user simply selects a parent category id from the admin using the plugin tab i have created.

To speed things up i have added block caching to the plugin using the following code

 $this->addData(array(
            'cache_lifetime' => 86400,
            'cache_tags' => array(Mage_Catalog_Model_Category::CACHE_TAG)
        ));

This works well so far, as if a sub category is enabled / disabled the cache invalidates and is replaced. However if i change the parent category id in the admin changes are not seen until the whole block cache is refreshed using system->cache managment.

What i would like to do is have a method where by when a user clicks save in the admin the cache is flushed for just this one block rather than refreshing everything.

How would i go about this ? i am thinking some sort of event observer on the save event in adminhtml? however i wouldn't know how to do this.

I am interested on what thoughs / suggestions other people may have.

Many thanks

Ian Cassidy


回答1:


You can use an Event Observer to clean cache. You can follow this tutorial to setup your observers, and then observe the catalog_category_save_after event.

To clear cache, use Mage::app()->getCacheInstance()->cleanType(Mage_Catalog_Model_Category::CACHE_TAG); in your Observer Model.

PS: maybe you have to setup your <events> into <admin> or <adminhtml> instead of <globals>.




回答2:


you can use observer generate when click refresh action in cache management. after that , you can clear cache by cache tag or cache Id . This is solution to clearn cache by cache id. can you see how to refresh cache in custom cache type



来源:https://stackoverflow.com/questions/9588547/magento-refresh-cache-on-plugin-save

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