1
votes

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!

1
I'm having an issue understanding, what are you trying to accomplish? Active Record caching gives you the ability to re-use parts of your queries. For example, your ->where() would be put over to your next SQL statement. - Steven Lu
Steven, my requirement was to ensure that data is ALWAYS filtered by org_id and user_id from these tables. This can be done by active record caching, my confusion lay with inserting data wherein I also wanted to automate the insertion of these values. I think their docs were misleading to suggest that caching was available for the set method. My question now I suppose would be how i might go about automating the insertion of these two fields on all table insert queries. - idodev

1 Answers

1
votes

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.