EllisLab text mark
Advanced Search
     
Cache query?
Posted: 09 November 2012 01:09 AM   [ Ignore ]
Avatar
Joined: 2012-05-21
69 posts

I enable query cache in this way:
1-config/database.php
TRUE for cache query and set cache folder.
2-Change cache folder permission to 777.

Now when I want to cache a query I use $this->db->cache_on(); before query and after that I use $this->db->cache_off();

Now I have one question:
All queries cached or just query with cache_on cached?
Just I need to cache queries with cache_on.

 
Posted: 09 November 2012 11:50 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2012-05-21
69 posts

No one can help me?
It is really important for me.

 
Posted: 10 November 2012 09:43 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-11-10
2 posts

You don’t need to enable cache query on config/database.php.
If you set TRUE cache query on config/database.php ALL the queries are by default cached.
If you only want to cache specific queries set FALSE cache query on config/database.php and then you need to write $this->db->cache_on() before the query and this cached all the queries after that on the same function of the model (only on the function).

If your function have multiple queries and you dont want that all was cached write $this->db->cache_on() before the queries you want to cache and write this->db->cache_off() before the queries you don’t want to cache.

Important is that you set the cache directory on config/database.php with the full path of the server.

(Sorry by my english, I’m spanish)

 
Posted: 10 November 2012 10:45 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2012-05-21
69 posts

I set query cache false in config/database.php
and some queries don’t have this->db->cache_off() what happen for them?

 
Posted: 10 November 2012 11:10 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-11-10
2 posts

These queries was then cached if on the function of the model there are a $this->db->cache_on() before.

Example: on a model

public function example1() {

query 1

$this->db->cache_on()
query 2

query 3

$this->db->cache_off()
query 4

query 5

$this->db->cache_on()
query 6

}

public function example2()
{

query 7

}

“query 1” is not cached because the default cache is FALSE.
“query 2” is cached.
“query 3” is cached.
“query 4” not is cached.
“query 5” not is cached.
“query 6” is cached.
“query 7”, that is on other function not is cached.
....

 
Posted: 11 November 2012 12:13 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2012-05-21
69 posts

Very good example.
This solved my problem.