1

好的,问题来了:

$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".

4

3 回答 3

3

好吧,按照我回答自己问题的传统,这里有答案,还有一个子问题,如果有人知道发生了什么:

基本上,如果你碰巧运行了比 Hello World 更高级的东西,这个东西就不能开箱即用。我有一个 cookie 集,因为它找到了一个 cookie,它拒绝对此做任何事情,所以在缓存代码中挖掘了一个小时,我发现所需的魔法只是设置

'cache_with_cookie_variables' => true,

好吧,因为所有 cookie 或多或少都是独一无二的,我真的不想关心它们,所以我设置

'make_id_with_cookie_variables' => false

所以现在它完美地工作了。

感谢 Chris 和 smoove 抽出时间,事后看来,您的评论很有意义。当然,我没有任何错误或警告,而且“文件”确实是用大写字母拼写的。

我现在想知道的是我是否可以在某些情况下发送一个尖峰来删除正确的缓存文件。我可以锤击它(复制缓存中的 ID 生成器并 unset() 正确的目标),但可能有一个更好的解决方案。如果您有任何想法,请告诉我。

于 2009-10-01T08:48:45.390 回答
0

请转到config/application.ini并设置:

resources.frontController.params.disableOutputBuffering = true
于 2012-04-02T12:20:59.543 回答
0

如果您完成了 config/application.ini ,只需复制并粘贴下面的代码即可享受乐趣。请记住临时文件;我在这里使用过服务器缓存,您可以使用 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();
于 2012-04-02T12:25:47.670 回答