CodeIgniter: How to enable and clear cache _ php instance

Source: Internet
Author: User
Tags codeigniter
Codeigniter supports the caching technology to achieve the fastest speed. Depending on the Web cache, your web page can load almost static Web pages because they save the results output by the program to the hard disk. This article describes how to enable and clear the cache by CodeIgniter. For more information about how to use Codeigniter to enable and clear the cache, see how CodeIgniter supports the cache technology to achieve the fastest speed. Although CI has been quite efficient, factors such as the dynamic content in the webpage, the memory CPU of the host, and the read speed of the database directly affect the loading speed of the webpage. Depending on the Web cache, your web page can load almost static Web pages because they save the results output by the program to the hard disk.

How does cache work?

CI supports separate cache for each page and allows you to set the cache Update time. When a webpage is loaded for the first time, the cached file is saved to the application/cache folder. During the next visit, the system will directly read the cached file and return it to the user's browser. If the cached file expires, it will be deleted and regenerated.
Note: The Benchmark label is still available on the page that uses the cache.

Start cache

To enable the caching function, you only need to put the following code in the function of any controller:

The Code is as follows:

$ This-> output-> cache (n );


N indicates the number of minutes in which you want to cache updates. You can use m/60 to get accurate to the second. For example, 1/60 is accurate to 1 second.
The above code can be put in any function. The order of appearance does not affect the cache, so place it where you think it is most logical. Once the above Code is put into the Controller method, the page will be cached.
Warning because CI stores cached files, only the view File output can be cached.
Note: Before the cache file is generated, make sure that the application/cache folder is writable.

Clear Cache

If you no longer want to use the cache, you only need to delete the above Code from your controller. Note: This will not cause the cached file to disappear immediately. It will automatically expire and be deleted. If you want to delete those files immediately, you must do it yourself.

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.