Welcome Guest, Not a member yet? Register   Sign In
Caching based on content blocks
#1

[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


Messages In This Thread
Caching based on content blocks - by El Forum - 01-11-2008, 03:48 AM
Caching based on content blocks - by El Forum - 01-11-2008, 02:36 PM
Caching based on content blocks - by El Forum - 01-12-2008, 04:19 AM
Caching based on content blocks - by El Forum - 01-12-2008, 07:06 AM
Caching based on content blocks - by El Forum - 01-14-2008, 01:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB