简体   繁体   中英

CodeIgniter - Active Record Caching for an insert query

I am currently attempting to create a fairly basic web app that has the potential to hold sensitive(ish) data for users and their organizations.

I had intended on storing all user entered record data in one db and all app data in another db.This data will be stored in a shared db with an user_id and org_id against all records in all tables to facilitate separation.

To minimize risk of code error and data compromise I have researched the ability to automatically append standard 'where' statements to my active record queries using Active Record Caching

$this->db->start_cache();
$this->db->where('user_id',$_SESSION['user_id']);
$this->db->where('org_id',$_SESSION['org_id']);
$this->db->stop_cache();

This is brilliant and will save a lot of headaches. However, According to the documentation http://codeigniter.com/user_guide/database/active_record.html#caching I should also be able to use this for updates (set method):

Note: The following statements can be cached: select, from, join, where, like, group_by, having, order_by, set.

Looking at the active_record class "DB_active_rec.php" there is code present to provide caching in several methods (select, where etc).

if ($this->ar_caching === TRUE)
{
...do caching stuff

From what I can tell this seems to be missing from the set method.

I'm not sure what answer I'm after but hopefully it will be that I'm just doing it wrong!

You can't cache update statements. It would not make much sense. In your update you use the $this->db->where() method, which essentially is a select. That part can be cached, and by doing that you save yourself a select statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM