【发布时间】:2012-01-10 22:31:26
【问题描述】:
我正在尝试使用 Zend_Cache,所以我在我的操作中添加了以下代码(我猜稍后将移至引导程序):
$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? -
觉得这很简单 ;) 将其添加为答案,这样我就可以将其标记为已解决并给你一些积分。
标签: zend-framework