Welcome Guest, Not a member yet? Register   Sign In
Cache query?
#1

[eluser]Hamed[/eluser]
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.
#2

[eluser]Hamed[/eluser]
No one can help me?
It is really important for me.
#3

[eluser]cyoarte[/eluser]
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)
#4

[eluser]Hamed[/eluser]
I set query cache false in config/database.php
and some queries don't have this->db->cache_off() what happen for them?
#5

[eluser]cyoarte[/eluser]
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.
....
#6

[eluser]Hamed[/eluser]
Very good example.
This solved my problem.




Theme © iAndrew 2016 - Forum software by © MyBB