• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cache query?

I enable query cache in this way:
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.

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

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)

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

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

query 2

query 3

query 4

query 5

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.

Very good example.
This solved my problem.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.