Welcome Guest, Not a member yet? Register   Sign In
Cached Queries and DB sessions
#1

[eluser]SneakyDave[/eluser]
I plan to use Query Caching and CI's session library in a future project, and plan to store the sessions in the database.

Just because I was wondering, if query caching is turned on, does it cache the session table queries also? If so, are there any security concerns about doing that? Do I need to manually delete the session table query cache whenever a new session is created, or does CI manage that automatically, or can I turn off caching of the session table queries?
#2

[eluser]Hannes Nevalainen[/eluser]
You can disble cache for queries if you want:
Code:
// Turn caching on
$this->db->cache_on();
$query = $this->db->query("SELECT * FROM mytable");

// Turn caching off for this one query
$this->db->cache_off();
$query = $this->db->query("SELECT * FROM members WHERE member_id = '$current_user'");

// Turn caching back on
$this->db->cache_on();
$query = $this->db->query("SELECT * FROM another_table");
(Copied from the userguide)

Regards
#3

[eluser]SneakyDave[/eluser]
Yes, but the DB session calls are done "behind the scenes", aren't they? I wouldn't know when to turn caching on or off, because I don't know when those DB calls are made to the session table.

I guess I could go through the session library or extend it and find all the queries it makes to the database, and turn off caching for each of those database queries.

I was hoping that maybe session table queries were excluded from caching, or if they weren't, if that would present any problems.
#4

[eluser]Hannes Nevalainen[/eluser]
Oh, sorry i missunderstood your question (my bad). Hopefully the devteam behind DB-sessions has thought about this issue =)

Othewise you can allways make a quick testrun in an sample app =)
#5

[eluser]SneakyDave[/eluser]
I've done some simple tests and looked at the session code, and it seems that session queries are also cached if database caching is turned on. I haven't noticed a problem as of yet (not that far along), but I would think I'd need to clear that cache once a session was deleted or added to the session table I'm using.

I think I'll just try to manually turn on caching for the queries that will benefit from it.




Theme © iAndrew 2016 - Forum software by © MyBB