我想缓存 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/