Welcome Guest, Not a member yet? Register   Sign In
AR library : remove cache methods?
#1

[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?
#2

[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.
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB