Zend 缓存不启动

发布于 2024-08-06 10:02:08 字数 722 浏览 3 评论 0原文

好吧,问题来了:

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

Ok, here's the problem:

$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();

This doesn't do anything at all. Page loading times are exactly the same and the folder indicated in $backendOptions is empty. What am I doing wrong?

By the way: $config->cache->backend reads "file".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

远山浅 2024-08-13 10:02:08

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

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

'cache_with_cookie_variables' => true,

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

'make_id_with_cookie_variables' => false

所以现在它工作完美。

感谢 Chris 和 smoove 抽出时间,现在事后看来,你们的评论很有意义。当然,我没有任何错误或警告,并且“文件”确实是大写的。

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

Well, following my tradition of answering my own questions, here comes the answer, and a subquestion, if anyone knows what's going on:

Basically, this thing doesn't work out of the box if you happen to run something more advanced than Hello World. I had a cookie set and since it found a cookie, it refused to do anything about it, so one hour digging in the caching code I discovered that the magic needed was simply to set

'cache_with_cookie_variables' => true,

And well, since all cookies are more or less unique and I don't really want to care about them, I set

'make_id_with_cookie_variables' => false

So now it works flawlessly.

Thanks to Chris and smoove for taking the time out and now in hindsight your comments made a lot of sense. Naturally though, I didn't have any errors or warnings and "File" was indeed spelled with uppercase.

What I wonder now is if I can send a spike to delete the proper cache file upon certain circumstances. I can hammer it (copy the ID generator in the cache and unset() the proper target), but there might be a fancier solution. If you have any idea, let me know.

尴尬癌患者 2024-08-13 10:02:08

请前往 config/application.ini 并设置:

resources.frontController.params.disableOutputBuffering = true

Please go to config/application.ini and set:

resources.frontController.params.disableOutputBuffering = true
孤独岁月 2024-08-13 10:02:08

如果您已完成 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();

If you are done with config/application.ini , just copy and past the code below and have fun.
Please do remember the temporary file ; I have used here servercache you can use temp or tmp or whatsoever.

$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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文