Step-1: Initially, create a controller
cache.php
and store it in the path
application/controller.
[php]
<?php
class Cache extends CI_Controller
{
public function index() {
$this->output->cache(1);
$this->load->view('cache_view');
}
public function delete_file_cache() {
$this->output->delete_cache('cache');
}
}
?>
[/php]
Step-2 : Then create the view file cache_view.php in
application/views folder.
[html]
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>CodeIgniter View Example</title>
</head>
<body>
CodeIgniter View Example
</body>
</html>
[/html]
Step-3 : Then add the routes for above created controller in
routes.php
file present in
application/config and enter the below code at the end of the file.
[html]
$route['cache'] = 'Cache';
$route['cache/delete'] = 'Cache/delete_file_cache';
[/html]
Now, to see the output enter the below URL in the browser.
[html]http://localhost/Codeigniter/index.php/cache[/html]
Output:
Once the URL is visited, a cache file with some random name is created in the path
application/cache like below.
In order to delete the cache file, enter the below URL.
[html]http://localhost/Codeigniter/index.php/cache/delete[/html]
Then the output page will be empty without any result.