Site icon Shyam Makwana

CodeIgniter : Dynamic Database Query Caching

Purpose: This article is intended to show you how you can disable query caching for particular methods and enable it globally for all methods.

In CodeIgniter there is default option for query caching. If you enable query cache in database.php, by passing $db['default']['cache_on'] = TRUE; It will enable query cache for all controllers.

You might be thinking that there are already defined methods to on/off caching. But what if you have large application with hundreds of methods. You won’t like to open every file and put $this->db->cache_on() and $this->db->cache_off() for all functions.

Thus setting cache_on to TRUE is only option. What if you want to disable caching for particular method call ? Here is a solution.

Hacking Core for Dynamic Query Caching

In your following files make following changes according to git embed script below.

/application/config/config.php
/system/database/DB_cache.php

 

Thank you.

Enjoy…!!!

Exit mobile version