CodeIgniter Page Caching - CodeIgniter

What is CodeIgniter Page Caching?

Caching a page will enhance the web page load speed. If the page is cached, then it will be kept in its totally reduced state. Next time, when the server receives a request for the cached web page, it is going to be straightly dispatched to the inquired browser.

Cached documents are kept in application/cache folder. Caching can be enabled on according to page foundation. While allowing the cache, we need to set the time, till which it needs to stay in a cached folder and after that period; it will likely be deleted automatically.

How to Enable Caching?

Caching can be enabled by executing the following line in any of the controller’s method.

Where $n is the number of minutes, you wish the page to remain cached between refreshes.

How to Disable Caching?

Cache file gets deleted when it expires but when you want to delete it manually, then you have to disable it. You can disable the caching by executing the following line.

Example

Create a controller called Cache_controller.php and save it in application/controller/Cache_controller.php

Make a view file called test.php and save it in application/views/test.php

Change the routes.php file in application/config/routes.php to add route for the above controller and add the following line at the end of the file.

Type the following URL in the browser to execute the example.

After visiting the above URL, you will see that a cache file for this will be created in application/cache folder. To delete the file, visit the following URL.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

CodeIgniter Topics