CI framework database query Cache Optimization Method, ci framework database cache

Source: Internet
Author: User

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 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.