[eluser]Unknown[/eluser]
Hello everyone.
I'm looking for a way to cache my output, before gathering data. CI seems to support per-page caching only, which won't do in this situation. Imagine a contentpage, which contains various blocks. Each block has it's own template and thus each block has its own cache with it's own lifetime.
I've thought of the solution below, and I'm quite content with its functionality. What bothers me is the fact that I need to call and check for cache in every template-returning method.
The question: can anyone think of a way to automate this call?
Code:
<?php
class HomepageController {
// Gather data for homepage
public function index()
{
$data['images'] = $this->images( );
$data['content'] = $this->content( );
$this->load->view( 'homepage', $data );
}
// Pseudo code, fetch images
public function images( )
{
if ($this->ib_cache->is_cached( 'homepage/images', 14 ) )
return $this->ib_cache->get_cache( 'homepage/images' );
else
{
$this->load->model( 'ImageModel' );
$data['images'] = $this->ImageModel->get_newest_images( 5 );
return $this->load->view( 'images', $data, true );
}
}
// Pseudo code, fetch content
public function content( )
{
if ($this->ib_cache->is_cached( 'homepage/content', 8 ) )
return $this->ib_cache->get_cache( 'homepage/carousel' );
else
{
$this->load->model( 'ContentModel' );
$data['content'] = $this->ContentModel->get_page( 'home' );
return $this->load->view('content', $data, true);
}
}
?>
Thanks in advance