CodeIgniter Forums
Caching question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Caching question (/showthread.php?tid=40478)



Caching question - El Forum - 04-10-2011

[eluser]shadow player[/eluser]
Hello all

I'm fairly new to Codeigniter. I have been reading the user guide extensively but one question has remained open for me.

Consider this scenario:
An article page, completely static with only one little dynamic text displaying the number of views this article has got.

How could I cache such a page in order to serve it fast but still update the views counter?

Any answer will be greatly appreciated,
Tom


Caching question - El Forum - 04-10-2011

[eluser]John_Betong_002[/eluser]
 
I do not think there is an easy solution Sad

Recently I have introduced DB Caching do some dynamic pages and it appears to be working fine.

 
 


Caching question - El Forum - 04-11-2011

[eluser]bubbafoley[/eluser]
Reactor has a caching driver.

Use it in a controller like this:
Code:
$this->load->driver('cache', array('adapter'=>'file'));

if( ! $article = $this->cache->get('article_1'))
{
    $article = $this->article_model->get_article(1);
}

$article['views']++;
$this->cache->save('article_1', $article);

Read more: http://www.gregaker.net/2011/feb/12/codeigniter_reactors_caching_drivers/


Caching question - El Forum - 04-12-2011

[eluser]Nick_MyShuitings[/eluser]
For dinky little widgets like that, I usually call them in using AJAX. It allows you to quickly and completely cache the entire view using even default frontend caching, and the ajax quickly pings a controller method and gets the count and updates the html. That was my old way of doing it, I'm very much liking what bubbafoley is suggesting above, and think I'll try it with my memcached setup.