2013-06-18 75 views
1

我使用這個功能bootstrap.php中緩存我的控制器,我需要緩存某些控制器只有我不需要索引緩存控制器和文章控制器爲例 和我需要緩存問題控制器,但它不起作用。此功能緩存所有我的控制器的Zend緩存前端

protected function _initCache() 
{ 
    mb_internal_encoding("UTF-8"); 
    $dir = "/var/www/data/cache/all"; 

    $frontendOptions = array(
     'lifetime' => 3600, 
     'content_type_memorization' => true, 
     'default_options'   => array(
     'cache' => true, 
     'cache_with_get_variables' => true, 
     'cache_with_post_variables' => true, 
     'cache_with_session_variables' => true, 
     'cache_with_cookie_variables' => true, 
     ), 
    'regexps' => array(

      '^/$' => array('cache' => false), 
      "^/question/" => array('cache' => true), 
      "^/article/" => array('cache' => false), 
      ) 
    ); 
    $backendOptions = array(
      'cache_dir' =>$dir 
    ); 

    // getting a Zend_Cache_Frontend_Page object 
    $cache = Zend_Cache::factory('Page', 
         'File', 
         $frontendOptions, 
         $backendOptions); 

    $cache->start(); 
} 

所以我能做什麼我試過所有的解決方案,請幫助我。 謝謝

回答

0

使用該代碼創建一個控制器插件,並檢測請求。 喜歡的東西...

if($request->getControllerName() == 'index' || ... == 'article') { 
return; 
} 
mb_internal_encoding("UTF-8"); 
... 
+0

謝謝你,我不喜歡你的解決方案出頭,但使用 $在我的函數初始化請求= $ _ SERVER [「REQUEST_URI」]; 如果($請求== '條每頁'){ /*我的功能做緩存*/ } 非常感謝 –

+0

不好的做法,做到這一點。試試這個。 http://pastebin.com/TGKywun3 –