CodeIgniter Forums
AR library : remove cache methods? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: AR library : remove cache methods? (/showthread.php?tid=11932)



AR library : remove cache methods? - El Forum - 09-29-2008

[eluser]xwero[/eluser]
Lately i'm beginning to wonder if there is the real benefit when using the cache methods?

A lot of people use the cache methods when they have to get two different things from the same table like the number of rows and the rows themselves but most of the times the num_rows method is sufficient.

Instead of the cache methods i'm starting to use arrays and variables for not having to redefine the sql statement parts.
Code:
$this->db->start_cache();
$this->db->from('table');
$this->db->where(array('id'=>1,'time'=>'12:00:00'));
$this->db->stop_cache();

$this->db->select('number');
$query1 = $this->db->get();

$this->db->select('name');
$query2 = $this->db->get();
$this->db->flush_cache();
// VS
$table = 'table';
$where = array('id'=>1,'time'=>'12:00:00');  

$this->db->select('number');
$this->db->from($table);
$this->db->where($where);
$query1 = $this->db->get();

$this->db->select('name');
$this->db->from($table);
$this->db->where($where);
$query2 = $this->db->get();
Normally i'm not found on copying lines but once the queries are getting more complex i noticed the cache methods are more in the way than helping to reduce the code i have to write. Not adding the flush_cache method caused me a lot of time loss. When using variables and arrays you don't have to flush the DB object values.

What is your view on the cache methods?


AR library : remove cache methods? - El Forum - 09-29-2008

[eluser]m4rw3r[/eluser]
I'm quite neutral, but I like to be able to shorten my code Smile.

I really think it depends on the situation if it is suitable or not.


AR library : remove cache methods? - El Forum - 09-29-2008

[eluser]xwero[/eluser]
I agree with you that it depends on the situation but I think the alternatives, using variables/arrays and this feature request, are more useful in all sorts of situations than the caching methods.