Zend页面缓存类似于smarty?
我有办法让 zend_cache 对待前端视图类似于 smarty 吗?我想减少加载时间,页面缓存似乎是做到这一点的最佳方法。
它还需要类似于 {nocache} 的东西。
好的,我现在有了: Bootstrap.php
protected function _initCache() {
$this->bootstrap('locale');
$locale = $this->getResource('locale');
$front = array ( 'lifetime' => 1800,
'automatic_serialization' => false,
'caching' => true,
'cache_id_prefix' => 'ec_',
'debug_header' => true,
'default_options'
=> array ('cache_with_get_variables' => true,
'cache_with_post_variables' => false,
'cache_with_session_variables' => false,
'cache_with_cookie_variables' => false ),
);
$back = array('cache_dir' => '../data/Cache/'.$locale);
$cache = Zend_Cache::factory('Page', 'File', $front, $back);
$cache->start();
Zend_Registry::set('cache', $cache);
return $cache;
}
但是,唯一一次命中我的缓存的是使用如下代码:
$cache = Zend_Registry::get('cache');
if (!$data = $cache->load('sidebar_'.$module.'_'.$controller)) {
$data['Studio'] = Eurocreme_Studio::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => COUNT_HIGH));
$data['Movie'] = Eurocreme_Movie::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
$data['Gallery'] = Eurocreme_Gallery::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
$data['Category'] = Eurocreme_Category::load_tree(0);
$cache->save($data, 'my_view_helper_sidebar_'.$module.'_'.$controller);
}
我希望捕获整个视图。
有谁有关于如何充分实施它的工作示例吗?这些文档并没有真正深入。
I there a way to make zend_cache treat front end view similar to smarty? I would like to reduce load times and page caching seems the best way todo this.
Also it would need something similar to {nocache}.
Okay so I now have: Bootstrap.php
protected function _initCache() {
$this->bootstrap('locale');
$locale = $this->getResource('locale');
$front = array ( 'lifetime' => 1800,
'automatic_serialization' => false,
'caching' => true,
'cache_id_prefix' => 'ec_',
'debug_header' => true,
'default_options'
=> array ('cache_with_get_variables' => true,
'cache_with_post_variables' => false,
'cache_with_session_variables' => false,
'cache_with_cookie_variables' => false ),
);
$back = array('cache_dir' => '../data/Cache/'.$locale);
$cache = Zend_Cache::factory('Page', 'File', $front, $back);
$cache->start();
Zend_Registry::set('cache', $cache);
return $cache;
}
However, the only time my cache is hit is with code like:
$cache = Zend_Registry::get('cache');
if (!$data = $cache->load('sidebar_'.$module.'_'.$controller)) {
$data['Studio'] = Eurocreme_Studio::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => COUNT_HIGH));
$data['Movie'] = Eurocreme_Movie::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
$data['Gallery'] = Eurocreme_Gallery::load_by_type(array('type' => 'sidebar', 'from' => 0, 'to' => 5));
$data['Category'] = Eurocreme_Category::load_tree(0);
$cache->save($data, 'my_view_helper_sidebar_'.$module.'_'.$controller);
}
I was hoping to capture the entire views.
Does anyone have any working examples of how to implement it fully? The docs don't really go in-depth.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要使用
Zend_Cache_Frontend_Output
或Zend_Cache_Frontend_Page
。来自 Zend Framework 手册:Zend_Cache_Frontend_Output
是一个输出捕获前端。它利用 PHP 中的输出缓冲来捕获 start() 和 end() 方法之间的所有内容。Zend_Cache_Frontend_Page
与 Zend_Cache_Frontend_Output 类似,但专为完整页面而设计。You may want to use
Zend_Cache_Frontend_Output
orZend_Cache_Frontend_Page
. From Zend Framework manual:Zend_Cache_Frontend_Output
is an output-capturing frontend. It utilizes output buffering in PHP to capture everything between its start() and end() methods.Zend_Cache_Frontend_Page
is like Zend_Cache_Frontend_Output but designed for a complete page.您可能正在寻找
Zend_Cache_Frontend_Page
。有关详细信息,请参阅 Zend Cache 文档。You are probably looking for
Zend_Cache_Frontend_Page
. Please refer to Zend Cache docs for details.