开发者

Where to put cache clearing code

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?


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.


How about a service? Application_Service_Navigation (or whatever appnamespace you are using) stored in application/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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜