2

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

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

4

1 回答 1

3

使用debug_headertrue 和 check ,下面的代码。由于我们一开始设置不缓存所有页面,只缓存以 开头的页面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();
    }
}
于 2012-02-09T06:15:08.073 回答