zend-framework - Zend_Cache 缓存整个站点而不是 Controller

标签 zend-framework zend-cache

我想缓存 Controller ajax

<?php
class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
    public function _initCache()
    {
        $frontendOptions = array(
            'lifetime' => 10800,
            'automatic_serialization' => true,
            'debug_header' => false,
            'regexps' => array('^/ajax/' => array('cache' => true),
                               '^/admin/' => array('cache' => false)),
            'default_options' => array(
            'cache_with_cookie_variables' => true,
            'make_id_with_cookie_variables' => false));

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

        $cache->start();
    }
}

但是缓存整个网站,包括管理模块。

最佳答案

使用 debug_header 为 true 并检查下面的代码。由于我们一开始设置不缓存所有页面,只缓存以 ajax 开头的页面,所以我希望所有的ajax页面都以 ajax 开头,否则相应更改正则表达式。

class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
    public function _initCache()
    {
        $frontendOptions = array(
            'lifetime' => 10800,
            'automatic_serialization' => true,
            'debug_header' => true,                
            'regexps' => array(
                '$' => array('cache' => false),
                '/ajax' => array('cache' => true),
            ),
            'default_options' => array(
                'cache_with_cookie_variables' => true,
                'make_id_with_cookie_variables' => false
            )
        );

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

        $cache->start();
    }
}

关于zend-framework - Zend_Cache 缓存整个站点而不是 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9199188/

相关文章:

email - Zend Framework 2 的原始字符串电子邮件

c - Zend 哈希表 SIGSEGV

memory-management - Zend_Cache 反序列化 - 内存占用?

zend-framework - 如何使用Zend,l18n mysql为多语言数据库建模?

php - Zend Framework 复选框装饰器

php - Zend_Db_Table Select missing data,直接PHP查询ok

php - ZF : Disable Resource Plugin in application. ini

php - 文件中的 Zend 元数据缓存

php - 如何为 Zend Cache Storage 设置过期时间?