Zend_Cache缓存整个站点而不是控制器

时间:2012-02-08 18:23:23

标签: zend-framework zend-cache

我想缓存控制器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();
    }
}

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

1 个答案:

答案 0 :(得分:3)

使用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();
    }
}