Codeigniter supports caching technology to achieve the fastest speed. Although CI is already quite efficient, factors such as the dynamic content in the web page, the host's memory CPU and database reading speed directly affect the loading speed of the web page. Relying on web caching, your web pages can achieve a loading speed close to that of static web pages, because they save the output of the program to the hard disk.
How does caching work?
CI supports separate caching of each page, and the cache update time can be set. When a web page is loaded for the first time, cache files will be saved to the application/cache folder. The next time you visit, the system will directly read the cache file and return it to the user's browser. If the cache file expires, it will be deleted and regenerated.
Note: Benchmark tags are still available on pages that use caching.
Enable caching
To enable caching, just put the following code into the method (function) of any of your controllers:
Copy code The code is as follows:
$this->output->cache(n);
where n is The number of minutes you want to cache updates. You can use m/60 to be accurate to seconds. For example, 1/60 is accurate to 1 second
The above code can be placed in any function. The order in which they appear has no effect on caching, so place it where you think it makes the most sense. Once the above code is placed in the controller method, the page will be cached.
Warning: Due to the way CI stores cache files, only output via view files can be cached.
Note: Before the cache file is generated, please ensure that the application/cache folder is writable.
Clear cache
If you no longer want to use the cache, just delete the above code from your controller. Note: Doing this will not make the cache file disappear immediately, it will automatically expire and be deleted. If you want to delete those files immediately, you have to do it yourself.
http://www.bkjia.com/PHPjc/788635.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788635.htmlTechArticleCodeigniter supports caching technology to achieve the fastest speed. Although CI is already quite efficient, factors such as the dynamic content in the web page, the host's memory CPU and database reading speed directly affect...