CodeIgniter How to enable caching and clear caching _php instances
Source: Internet
Author: User
The CodeIgniter supports caching technology to achieve the fastest speed. Although CI is already quite efficient, the dynamic content in the Web page, the memory CPU of the host, and the speed of database reading directly affect the loading speed of the Web page. Depending on the page cache, your Web page can load almost static pages, because they save the results of the program output to the hard disk.
How does the cache work?
CI supports individual caching of each page, and can set cache update time. When a webpage is loaded for the first time, the cache file is saved to the Application/cache folder. The next time you visit, the system will read the cache file directly and return it to the user's browser. If the cache file expires, it will be deleted and regenerated.
Note: The benchmark tag is still available on pages that use the cache.
Start cache
To enable caching, simply place the following code within the method (function) of any one of your controllers (Controller):
Copy the Code code as follows: $this->output->cache (n);
where n is the number of minutes that you want the cache to update. The M/60 can be used to be accurate to seconds, for example 1/60, to 1 seconds.
The above code can be put into any function. The order of his appearance has no effect on caching, so put it where you think it is most logical. Once the above code is placed in the controller's method, the page is cached.
Warning: Due to the way CI stores cache files, only the output from the view file can be cached.
Note: Make sure that the Application/cache folder is writable before the cache file is generated.
Clear Cache
If you no longer want to use the cache, simply remove the above code from your controller. Note: This does not allow the cache file to disappear immediately, it will automatically expire and be deleted. If you want to delete those files immediately, you have to do it yourself.
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