Mario
Mario

Reputation: 885

codeigniter output cache doesn't work?

I'm using $this->output->cache(n) to cache webpage, but i cannot figure out how does it work.. I didn't find any cache files under system/cache folder...and also after I edit the page and show it again, the content changes, so it seems that the page is not really cached. Can anyone give a help? (i'm using phil's template lib) my code:

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

}

THANKS!

Upvotes: 1

Views: 4484

Answers (3)

Thanh Phan
Thanh Phan

Reputation: 11

Are you sure your application/cache directory has the correct permissions?

you you to directories application/cache in cpanel , permissions become 777 is OK

Upvotes: 1

John Magnolia
John Magnolia

Reputation: 16803

Debug this file and check it's actually writing the cache: 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);
}

This works well for me:

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;
    }

Upvotes: 1

Colin Brock
Colin Brock

Reputation: 21575

Two things, as outlined in the documentation:

Warning: Because of the way CodeIgniter stores content for output, caching will only work if you are generating display for your controller with a view.

Perhaps not using the "native" views is an issue?

Additionally:

Note: Before the cache files can be written you must set the file permissions on your application/cache folder such that it is writable.

Are you sure your application/cache directory has the correct permissions?

Upvotes: 3

Related Questions