2009-09-30 57 views
1

好踢,這裏的問題:Zend的緩存不中

$frontendOptions = array(
    'lifetime' => 7200, 
    'debug_header' => true, // for debugging, but it doesn't work... 
    'regexps' => array(

     // Cache the static pages 
     '^/pages/' => array('cache' => true), 
    ) 
); 

$backendOptions = $config->cache->backOptions->toArray(); 

// getting a Zend_Cache_Frontend_Page object 
require_once 'Zend/Cache.php'; 
$cache = Zend_Cache::factory('Page', 
    $config->cache->backend, 
    $frontendOptions, 
    $backendOptions); 

$cache->start(); 

這並不做任何事情。頁面加載時間完全相同,並且$backendOptions中指示的文件夾爲空。我究竟做錯了什麼?

順便說一句:$config->cache->backend讀取"file"

+0

你是直接在bootfile或index.php文件上調用它嗎? – Chris 2009-09-30 20:32:24

+0

究竟是/ pages /?你有一個「pageController()」?您可以嘗試'^/$'作爲正則表達式來測試匹配路徑是否存在問題。 錯誤日誌中的任何警告/錯誤/聲明? 你確定php有寫訪問到cachedirectory嗎? 而現在我可以想到的最後一件事情是:嘗試使用大寫'F'作爲後端的'文件'。 – smoove 2009-09-30 22:30:15

回答

3

好了,下面我回答我自己的問題的傳統,來這裏的答案,和subquestion,如果有誰知道這是怎麼回事:

基本上,這件事情並沒有現成的工作,如果你碰巧運行比Hello World更先進的東西。我有一個cookie集,並因爲它發現一個cookie,它拒絕做任何事情,所以一小時的緩存代碼挖我發現,魔術需要的是簡單的設置

'cache_with_cookie_variables' => true, 

和好了,因爲所有的餅乾都或多或少獨特的,我真的不想去關心他們,我所以現在它完美的作品集

'make_id_with_cookie_variables' => false 

感謝克里斯和smoove抽出時間,現在事後看來你的意見很有道理。當然,我沒有任何錯誤或警告,「文件」確實拼寫爲大寫。

現在我想知道的是,如果我可以在某些情況下發送尖峯來刪除正確的緩存文件。我可以錘擊它(將ID生成器複製到緩存中並取消設置()正確的目標),但可能有更好的解決方案。如果您有任何想法,請告訴我。

+1

你的回答對於方法是有價值的 http://blog.astrumfutura.com/archives/381-Zend-Framework-Page-Caching-Part-2-Controller-Based-Cache-Management.html – 2010-01-25 12:42:27

+0

哦..是一個不錯的頁面。 – John 2010-01-26 10:29:32

0

請到配置/的application.ini並設置:

resources.frontController.params.disableOutputBuffering = true 
0

如果您正在使用的config /的application.ini完成後,只需複製粘貼下面的代碼和樂趣。 請記住臨時文件;我已經在這裏使用了servercache,你可以使用temp或tmp或任何其他的。

$frontendOptions = array(
     'lifetime' => 900, 
     'automatic_serialization' => true, 
     'default_options' => array(
      '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, 
      'make_id_with_get_variables' => true, 
      'make_id_with_post_variables' => true, 
      'make_id_with_session_variables' => true, 
      'make_id_with_files_variables' => true, 
      'make_id_with_cookie_variables' => true, 
      'cache'=>true 
     ), 


    ); 

    $backendOptions = array(
     'cache_dir' => APPLICATION_PATH . '/servercache/' 
    ); 
    $cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions); 
    $cache->start();