2010-03-14 130 views
0

我有没有办法使zend_cache对待类似于smarty的前端视图?我想减少加载时间,页面缓存似乎是最好的办法。Zend页面缓存与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); 
      } 

我希望能捕捉整个看法。

有没有人有任何如何完全实现它的工作示例?这些文档并没有真正深入。

回答

1

您可能需要使用Zend_Cache_Frontend_OutputZend_Cache_Frontend_Page。来自Zend Framework manual

Zend_Cache_Frontend_Output是一个输出捕捉前端。它利用PHP中的输出缓冲来捕获start()和end()方法之间的所有内容。

Zend_Cache_Frontend_Page就像Zend_Cache_Frontend_Output,但设计为一个完整的页面。