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.
- In config file, there is an array containing list of URL’s to exclude from query caching.
- In DB_cache.php file there is a ‘write’ method which writes database to folder, there we put an condition that if URL found from that array then ‘return false;’. So it won’t save to that cache folder.