我想摆弄用Zend_Cache,所以我加了下面的代码到我的动作(将被移动后,以引导,我猜):Zend_Cache_Frontend_Page不承认输出没有回音
$frontendOptions = array(
'lifetime' => 7200,
'debug_header' => true, // für das Debuggen
'default_options' => array(
'cache' => true,
'cache_with_get_variables' => true,
'cache_with_session_variables' => true,
'cache_with_cookie_variables' => true,
'cache_with_post_variables' => true,
)
);
$backendOptions = array(
'cache_dir' => '/tmp/'
);
$cache = Zend_Cache::factory('Page', 'File',
$frontendOptions, $backendOptions
);
echo "hej";
var_dump($cache->start('someid'));
Zend的生成缓存现在包含hejbool(false)
的文件,但除此之外,它不会缓存我的页面。根据一本关于zend框架的德国书,false是有没有缓存可用是正确的。只有在找到缓存时返回true。
当我在Zend_Cache_Frontend_Page.php
内直接调试时,它下降到start() - 方法的底部,这意味着什么都没有出错(id给定)并且没有找到缓存,所以必须生成一个缓存。这已完成(我可以在/tmp/
中看到它),但没有所需的内容。
那么为什么不缓存Zend_View
的输出,但只能通过echo
直接输出?
我没有调用任何显式函数来渲染视图,但这似乎不再需要(我的视图总是根据控制器和动作自动呈现)。我为标准的XHTML模板(index.phtml
)和RSS模板(index.rss.phtml
)尝试了它。
任何想法?你需要其他代码片段吗?
有你在你的Bootstrap中添加了'Zend_Controller_Front :: getInstance() - > setParam('disableOutputBuffering',true)'或者'resources.frontController.params.disableOutputBuffering = true'到你的应用程序的配置文件中? – vstm 2012-01-09 20:28:57
认为这很容易;)添加它作为答案,所以我可以标记这个解决方案,并给你一些学分。 – Aufziehvogel 2012-01-09 20:35:11