缓存清除代码放在哪里
我目前正在组装一个基于 ZF 的 CMS,并且正在缓存我的 Zend_Navigation
对象以及由 renderMenu()
渲染的 html。因此,目前,每当菜单发生变化时,我都必须在相关操作中调用以下几行:
$cache = Zend_Registry::get("cache");
$cache->remove("menu");
$frontcache = Zend_Registry::get("frontcache");
$frontcache->remove("menuhtml");
我有一个 siteController 来处理菜单结构的更改,还有一个 pageController 来处理单个页面的添加/编辑/删除,因此代码用于这两个控制器的操作中。
我显然想将此代码放在一个可以调用的方法中,但最合适的位置在哪里?行动助手? siteController 和 siteController 的父类页面控制器?我应该组合控制器吗?或者其他什么?
I'm putting together a ZF based CMS at the moment, and am currently caching my Zend_Navigation
object, as well as the html rendered by renderMenu()
. So at the moment, whenever the menu changes, I have to call the following lines in the relevant action:
$cache = Zend_Registry::get("cache");
$cache->remove("menu");
$frontcache = Zend_Registry::get("frontcache");
$frontcache->remove("menuhtml");
I have a siteController to handle changes to the menu structure, and a pageController to handle add/edit/delete of individual pages, so the code is used in actions in both of these controllers.
I would obviously like to put this code in a single method I can call, but where would be the most appropriate place? An action helper? A parent class for siteController & pageController? Should I combine the controllers? Or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否考虑过使用操作助手(http://framework.zend。 com/manual/en/zend.controller.actionhelpers.html )?这将为您提供一个独立于控制器的位置,每个控制器仍然可以调用该位置。
Have you looked at using an Action Helper ( http://framework.zend.com/manual/en/zend.controller.actionhelpers.html )? This will give you a place that's independent of your controllers that each controller will still be able to call.
服务怎么样?
Application_Service_Navigation
(或任何您使用的appnamespace
)存储在application/services/Navigation.php
中,实现一个表示这两个中的CRUD操作的接口CMS 控制器。然后在内部,这些方法可以像您所描述的那样使用缓存。控制器调用服务方法并且不知道缓存操作。How about a service?
Application_Service_Navigation
(or whateverappnamespace
you are using) stored inapplication/services/Navigation.php
, implementing an interface representing the CRUD operations in those two CMS controllers. Then internally, these methods can use the cache as you have described. Controllers call the service methods and are unaware of the cache operations.