2012-04-10 41 views
1

我使用$this->output->cache(n)来缓存网页,但我无法弄清楚它是如何工作的。我没有在system/cache文件夹下找到任何缓存文件...并且在我编辑页面并再次显示它之后,内容改变,所以看起来这个页面并没有真正被缓存。任何人都可以提供帮助吗? (我用菲尔的模板LIB) 我的代码:codeigniter输出缓存不起作用?

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'); 

} 

谢谢!

回答

3

两件事情,as outlined in the documentation

警告:由于方式笨存储内容的输出,如果您是一个view控制器产生显示缓存才会工作。

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

此外:

注:缓存文件可以写之前,你必须设置文件权限您的应用程序/缓存文件夹,使得它是可写的。

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

+1

+1也许没有使用“原生”的观点是一个问题? – Philip 2012-04-10 15:59:37

+0

嗨科林和菲利普,谢谢你的回复!但是还有其他方法可以使用这种缓存方法吗?因为它似乎无法摆脱模板,我不得不使用它来构建网站......另外,如何更改权限?我无法在系统下找到缓存文件夹,但在应用程序下有一个缓存文件夹...对不起,我是CI新手 – Mario 2012-04-10 16:14:11

+0

@Mario:关于你最后一个问题,那是我的错。该目录确实是'application/cache'。关于如何让CI的缓存方法在没有CI视图的情况下工作,你必须看一下[Output class](http://codeigniter.com/user_guide/libraries/output.html)的“底层”,找到了解它的工作原理,并根据需要进行扩展。 – 2012-04-10 16:28:55

0

调试此文件,并检查它的实际写入高速缓存: 系统/核心/ 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; 
    } 
0

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

你你的目录应用程序/缓存中的cPanel,权限成为777 OK