0

我正在尝试缓存我的输出。我正在使用 Codeigniter 的内置功能 $this->output->cache() 但它不起作用。我的猜测是因为我使用的是树枝。有任何想法吗?

4

2 回答 2

2

我找到了答案,可能对经过这里的人有用。

$output = $this->twig->render('template.html'); // use render instead of display
$this->output->set_output($output); // use CI's output (autoloaded by default) manually
$this->output->cache(5); // cache for 5 minutes, doesn't matter where this line is in the function.
于 2013-02-27T04:09:14.780 回答
1

正如您自己发现的那样,您应该Output通过适当的方法之一将输出映射到类,以便利用其内置的缓存功能。请注意,目前在 Github 上开发的 CI 3.0 有一些您可能喜欢的更新(例如,保留所有输出标头的 gzip 缓存文件)。

您可以使用自定义方法扩展Loaderview(),并在那里执行逻辑,而不是在每个控制器中需要 2+ 行(如果您想加载多个文件,则每次都必须调用render()then )。append_output()

使用 Smarty 模板库正是这样做的。应该能够用 Twig 做类似的事情。(我也一直想把它移植过来,但没有时间。)

于 2013-02-27T04:39:45.177 回答