2

I am using codeigniter with MySQL.

One of my database is a price_table that is quite constant and gets "SELECT" quite often, the access where through the same model_function, so the query would be exactly the same. I think this should be a good example to implement MySQL cached query to improve performance.

I want to use codeigniter function to interact with database as much as possible, so I have codes like:

$q = $this->db->select('service_info.*, service_pricing.price, service_pricing.price_ID')
                    ->from('service_pricing')
                    ->where('status','active')
                    ->join('service_info','service_info.service_ID = service_pricing.service_ID ')
                    ->get();
if ($q->num_rows > 0) {
    return $q->result_array();
} else {return FALSE;}

I read about the Database Caching Class from codeigniter document, but I do not think this is what I want. The cache described here seems like a global one. In my case, I want it to be a few queries about a relatively constant database.

I am thinking something like this example:

SELECT SQL_CACHE id, name FROM customer;

Is there a good way I can do it in codeigniter? Thanks!

1
  • Have you tried my answer? It must work Commented Apr 11, 2015 at 19:56

1 Answer 1

1

You may set cache either global or specific to particular query. If you want to set cache to a query then use like following

$this->db->cache_on();
//your number 1 query here. this query will cache


 $this->db->cache_off();
 // number 2 query here. This query will not cached

hope clear now

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.