CI framework database query Cache Optimization Method, ci framework database cache
This article describes how to optimize the query cache of the CI framework database. We will share this with you for your reference. The details are as follows:
There is a good query optimization in the CI framework, that is, database cache optimization.
1. Enable Cache
// In application/config. enable $ db ['default'] ['cache _ on'] = TRUE in php; // In application/config. enable $ db ['default'] ['cachedir'] = 'in php '. /cache '; // Add a writable cache directory cache in the corresponding directory
2. Enable the cache statement in the corresponding Query
// Enable the cache switch $ this-> db-> cache_on (); $ query = $ this-> db-> query ("SELECT * FROM mytable "); // make the following query not cached $ this-> db-> cache_off (); $ query = $ this-> db-> query ("SELECT * FROM members WHERE member_id = '$ current_user '"); // Turn caching back on $ this-> db-> cache_on (); $ query = $ this-> db-> query ("SELECT * FROM another_table ");
3. Add the corresponding clear Cache
// The cache will not be automatically deleted. You can only manually delete the cache. // you can clear the cache in the corresponding add, modify, and delete statements. // clear all the caches. $ this-> db-> cache_delete_all () /* clear the example.com/index.php/blog/commentspage of a single cache. The cache system will put all generated cache files into a folder named "blog + comments. if you want to delete the cache file corresponding to this example, You need to execute the following code: */$ this-> db-> cache_delete ('/blog ', 'comments ');