active record query caching does not work like in the user guide - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: active record query caching does not work like in the user guide (/showthread.php?tid=1181) |
active record query caching does not work like in the user guide - tomasoma - 02-17-2015 Hi i run with CI-2.2.1 on a 1and1 "unlimited" linux web hosting, everything is fine until now, i'm very happy with CI. i wanted to try query caching to save some lines in my code but query caching creates a session_id field in my query : my table is : Code: mysql> describe ap_client ; the php is : PHP Code: $this->db->start_cache() ; and this render an error like Code: A Database Error Occurred where Line Number 53> PHP Code: $count = $this->db->count_all_results() ; Did i do something wrong, or i miss some configuration somewhere ? where does this session_id field come from ? I'm a lazy boy lol i have a lot more 'wheres' to add in these querys, query caching would be nice if it works. RE: active record query caching does not work like in the user guide - mwhitney - 02-17-2015 PHP Code: $this->admintab->order_by() RE: active record query caching does not work like in the user guide - tomasoma - 02-17-2015 (02-17-2015, 10:26 AM)mwhitney Wrote: OK yes this code works with the session, Ok i didn't know the session work with cached database query. Thank you very much, sorry for this newbie's Post. mmmm .... i wonder if we could name some cache to avoid this and it would give something like PHP Code: $this->db->start_cache('foo') ; Anyway thank you ! RE: active record query caching does not work like in the user guide - tomasoma - 02-17-2015 i'm pretty stupid i can also execute the piece of code above, it solves my problem.... *sigh* sorry RE: active record query caching does not work like in the user guide - mwhitney - 02-17-2015 The main thing to remember is that any active record activity between the start_cache and stop_cache calls is going to be included in the cached query. In your case, it was just hiding in another method. All of us do something like that from time to time, and it's a good reminder to be careful of unintended side-effects in our code. Generally, this is a good excuse to include a big comment mentioning that any database manipulation (including session handling) performed after start_cache() will be included in the cached query, so you (or someone else) don't accidentally create a similar problem later on. Also, while it's nice to be specific and probably helpful in translating SQL to active record, $this->db->select('*') isn't necessary, since it will automatically add 'select *' to the query if no calls are made to select(). On some databases, select * is also slower than explicitly stating the selected fields (though being explicit does mean you would have to update the query if you changed the table(s)) |