2011-05-08 29 views
2

我正在使用代码片段来缓存整个页面:Zend Framework:Zend_Cache_Frontend_Page在使用get参数时不缓存

<?php 

// Cache engine 
// Cache everything outputed on the page for 2 minutes 
// in the tmp folder 

require_once 'Zend/Cache.php'; 

$frontendOptions = array(
    'lifetime' => 120, 
    'automatic_serialization' => true, 
    '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 
); 

$backendOptions = array(
    'cache_dir' => '../tmp/' 
); 

$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions); 
$cache->start(); 

echo date("D M j G:i:s T Y"); 

?> 

如果我使用以下命令调用页面: http://localhost/myapp/cache.php 它完美地工作

如果我使用get参数调用页面: http://localhost/myapp/cache.php?test=5 页面未缓存

我使用ZF 1.11.0

感谢您的帮助!

回答

1

其实很容易,你有一个错误在你前端的选项,“cache_with_XXX_variables”需要在与键“default_options”的数组:

$frontendOptions = array(
    'lifetime' => 120, 
    'automatic_serialization' => true, 
    'default_options' => array(
      'cache' => true, 
      '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, 
     ) 
); 
+0

您救了我的命! – poiuytrez 2011-06-01 22:07:38

0

我认为你必须修改frontendOptions:

'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, 
+0

嗨,谢谢你的回复,但它仍然不起作用(并且它应该在没有你修改的情况下工作)。我的目标是让缓存工作,即使有一个get参数(我还没有通过获取值来获得一个id的步骤......)。现在,缓存完全无法使用get参数... – poiuytrez 2011-05-09 22:36:13