1

$this->output->cache(n)用来缓存网页,但我不知道它是如何工作的。我没有在system/cache文件夹下找到任何缓存文件……而且在我编辑页面并再次显示后,内容发生了变化,所以它似乎该页面并未真正缓存。有人可以帮忙吗?(我正在使用 phil 的模板库)我的代码:

function show(){

    $this->output->cache(5);

    $this->load->model('page_model');
    $var = $this->uri->segment(3, 0); //get About page
    $row = $this->page_model->getPage($var);
    $this->template->title('about')
                   ->set_layout('default')
                   ->set_partial('styles', 'css')
                   ->set('data', $row->body)
                   ->build('about');

}

谢谢!

4

3 回答 3

3

如文档中所述,有两件事:

警告:由于 CodeIgniter 存储输出内容的方式,缓存仅在您使用view为控制器生成显示时才有效。

也许不使用“本机”视图是一个问题?

此外:

注意:在写入缓存文件之前,您必须设置应用程序/缓存文件夹的文件权限,使其可写。

您确定您的application/cache目录具有正确的权限吗?

于 2012-04-10T15:54:07.653 回答
1

调试这个文件并检查它实际上是在写缓存:system/core/Output.php

// Do we need to write a cache file?  Only if the controller does not have its
// own _output() method and we are not dealing with a cache file, which we
// can determine by the existence of the $CI object above
if ($this->cache_expiration > 0 && isset($CI) && ! method_exists($CI, '_output'))
{
    $this->_write_cache($output);
}

这对我很有效:

function _output($content) {
        // Load the base template with output content available as $content
        $data['content'] = &$content;

        $this->output->cache(600);

        $output = $this->load->view('base', $data, true);

        $this->output->_write_cache($output);

        echo $output;
    }
于 2015-08-30T17:33:04.037 回答
1

您确定您的应用程序/缓存目录具有正确的权限吗?

你你到 cpanel 中的目录 application/cache ,权限变成 777 就可以了

于 2016-06-15T14:04:16.873 回答