我在 Zend Framework 1 中使用 Doctrine 1.2 。
我有很多控制器,我的布局中有侧边栏和右侧边栏,我在活动会话中有访问者和身份验证用户。
我做了一个基本的缓存方法,如:
$frontend= array('lifetime' => 3600);
$backend= array('cache_dir' => '/data/cache/FileName');
$cache = Zend_Cache::factory('core', 'File', $frontend, $backend);
if ((!$result = $cache->load('fileName'))) {
/* my code here*/
$cache->save($page, 'fileName');
} else {
$this->_helper->viewRenderer->setNoRender();
$this->getResponse()->appendBody($result);
}
但每次我需要在控制器中兑现现金页面时,我会在每个控制器中重复此代码,因此我想创建帮助程序,以管理所有案例和场景的现金,其中包含一组参数(文件名,生命时间,是日志)在用户,其他)和从左侧边栏布局兑现文件,并能够删除现金文件。 所以我只从我的控制器调用方法并从一个地方处理它。
在Zend框架中构建此缓存技术助手的最佳方法是什么?如果有的话 例子请帮助我,并为我提供最佳的构建方法。
感谢。
答案 0 :(得分:2)
您可以使用 Zend_Cache_Frontend_Page 并在您的zend bootstrap.php 中开始缓存。
喜欢:
$frontendOptions = array(
'lifetime' => '604800000',
'content_type_memorization' => false,
'default_options' => array(
'cache' => true,
'make_id_with_cookie_variables' => false,
'make_id_with_session_variables' => false,
'cache_with_get_variables' => true,
'cache_with_post_variables' => true,
'cache_with_session_variables' => true,
'cache_with_files_variables' => true,
'cache_with_cookie_variables' => true,
),
'regexps' => array(
'$' => array('cache' => true),
)
);
$backendOptions = array('cache_dir' => $yourDirectoryPath);
$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
$cache->start();
按照Zend Cache手册
中的教程进行操作http://framework.zend.com/manual/1.12/en/zend.cache.theory.html
答案 1 :(得分:0)
你真的需要缓存页面,为什么不只是缓存昂贵的数据?
在Zend Framework 1中,插件加载到每个控制器ZF1 Custom Plugins
上或仅在某些地方ZF1 Action Helpers
使用动作助手