CodeIgniter Forums
Database caching confusion - 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: Database caching confusion (/showthread.php?tid=56648)



Database caching confusion - El Forum - 01-09-2013

[eluser]blowmenow[/eluser]
Hi there folks.
Ive got a very serious problem. I cannot see a deferents between those snippets:

Code:
$this->db->cache_on();

and

Code:
$this->db->start_cache();

I'm really confused, are there many types of database caching? Or it is just redundant code? Explain it to me. Thank you!.


Database caching confusion - El Forum - 01-09-2013

[eluser]Otemu[/eluser]
$this->db->cache_on();
Manually enables caching.
http://ellislab.com/codeigniter/user-guide/database/caching.html

$this->db->start_cache()
This function must be called to begin caching. All Active Record queries of the correct type (see below for supported queries) are stored for later use.
http://ellislab.com/codeigniter/user-guide/database/active_record.html




Database caching confusion - El Forum - 01-09-2013

[eluser]blowmenow[/eluser]
So where is the different?
Both enable/disable caching. I can't see the point.
With one I suppose to use? It seems pointless.


Database caching confusion - El Forum - 01-09-2013

[eluser]Otemu[/eluser]
Sorry I left a huge chunk out when I copied and pasted before

Active Record Caching

While not "true" caching, Active Record enables you to save (or "cache") certain parts of your queries for reuse at a later point in your script's execution. Normally, when an Active Record call is completed, all stored information is reset for the next call. With caching, you can prevent this reset, and reuse information easily.

Cached calls are cumulative. If you make 2 cached select() calls, and then 2 uncached select() calls, this will result in 4 select() calls. There are three Caching functions available:

I assume then $this->db->cache_on(); is for active records, if both functions work then don't stress about it an just use $this->db->cache_on()


Database caching confusion - El Forum - 01-09-2013

[eluser]blowmenow[/eluser]
Oh, alright, separated cache switch for database with and without active record. This make some sense.

Code:
$this->db->start_cache();
$this->db->stop_cache();
has no effect when active records is ON.

This is very poorly designed.


Database caching confusion - El Forum - 10-07-2013

[eluser]Unknown[/eluser]
start_cache() is queries cache.
cache_on() is result cache.