Magento在插件保存时刷新缓存 [英] Magento refresh cache on plugin save

查看:88
本文介绍了Magento在插件保存时刷新缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的Magento插件,该插件仅列出了从给定父ID启用的所有子类别.

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

用户只需使用我创建的插件标签从管理员中选择父类别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)
        ));

到目前为止,此方法运行良好,就像启用/禁用了子类别一样,缓存无效并被替换.但是,如果我在管理中更改了父类别ID,则只有在使用system-> cache management刷新整个块缓存后才能看到更改.

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.

我将如何处理?我在想在adminhtml中的save事件上使用某种事件观察器?但是我不知道该怎么做.

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.

非常感谢

伊恩·卡西迪

推荐答案

您可以使用事件观察器清除缓存.您可以按照本教程设置观察者,然后然后观察catalog_category_save_after事件.

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.

要清除缓存,请在观察者模型中使用Mage::app()->getCacheInstance()->cleanType(Mage_Catalog_Model_Category::CACHE_TAG);.

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

PS:也许您必须将<events>设置为<admin><adminhtml>而不是<globals>.

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

这篇关于Magento在插件保存时刷新缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆