2012-01-09 57 views
0

我想摆弄用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)尝试了它。

任何想法?你需要其他代码片段吗?

+0

有你在你的Bootstrap中添加了'Zend_Controller_Front :: getInstance() - > setParam('disableOutputBuffering',true)'或者'resources.frontController.params.disableOutputBuffering = true'到你的应用程序的配置文件中? – vstm 2012-01-09 20:28:57

+0

认为这很容易;)添加它作为答案,所以我可以标记这个解决方案,并给你一些学分。 – Aufziehvogel 2012-01-09 20:35:11

回答

1

使用Zend_Cache_Frontend_Page时,必须启用disableOutputBuffering选项。原因是Zend_Cache_Frontend_Page使用ob_start进行回拨,并且必须是第一次拨打ob_start,否则会导致您遇到的奇怪行为。

要启用它,您可以用

Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering', true); 

设置在你的引导或使用配置文件的frontController-设置(在INI风格的配置这里)后:

resources.frontController.params.disableOutputBuffering = true