Zend缓存没有启动

时间:2009-09-30 15:15:29

标签: zend-framework zend-cache

好的,这是问题:

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

3 个答案:

答案 0 :(得分:3)

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

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

'cache_with_cookie_variables' => true,

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

'make_id_with_cookie_variables' => false

所以现在它完美无缺。

感谢Chris和smoove抽出时间,现在事后回顾你的评论很有道理。当然,我没有任何错误或警告,“文件”确实拼写为大写。

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

答案 1 :(得分:0)

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

resources.frontController.params.disableOutputBuffering = true

答案 2 :(得分: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();
相关问题