Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Cache
#1

[eluser]rallport[/eluser]
Have been using CI for a couple of weeks now and am loving it Smile I been looking at the forum a lot and decided to register.

I'm aware CodeIgniter has a pretty basic caching library as standard (but am aware there are a couple of PEAR style CodeIgniter cache libraruies about like http://philsturgeon.co.uk/code/codeigniter-cache). Say I did the following in a controller:

Code:
function index()
{
$this->load->model('data_model');
$data['rows'] = $this->data_model->getAll();
$this->output->cache(2);
$this->load->view('blog/blog_view', $data);
}

.. this should cache my view - blog/blog_view for 2 mins, which it does. However, am I not still making a call to the database? In the past, any caching librraies I've used, such as PEAR cache lite do the following:

Code:
$cache_id = '1234';
if (have_cache($cache_id)) {
  //load cache file
} else {
  //display page as normal
  save_cache_file();
}

Is Codeigniter doing a similar thing, or is the database call being made anyway?

Thanks
#2

[eluser]Twisted1919[/eluser]
When using the $this->output->cache() the entire output is generated and cached. Next time when a request is made, is the cache file for that page is already created, it will be served without hitting the database.
Note that output->cache() is based on uri segments.

I assume that using Phil's cache library gives you more flexibility, as you can cache page fragments or database results or array/objects, and is pretty easy to use.
#3

[eluser]rallport[/eluser]
Ah thanks. Was just wondering, as all the caching libraries I've used had a similar style to the bit of code I posted Smile




Theme © iAndrew 2016 - Forum software by © MyBB