-
Notifications
You must be signed in to change notification settings - Fork 26
Clear Page Cache
Category:Library | Category:Library::Community | Category:Library::Cache
Delete the cache for the current page or for the page at the URI supplied by the first parameter.
[code]// Deletes the current page's cache; $this->output->clear_page_cache();[/code]
[code]// Deletes the cache for "/welcome/index"; $this->output->clear_page_cache('welcome/index')[/code]
[code]// Deletes the exact cache file 67d8b8110269ea53756e4d7090152bfc; $filepath = $this->config->item('cache_path').'67d8b8110269ea53756e4d7090152bfc'; $this->output->clear_page_cache(null, $filepath);[/code]
For flashdata, call it before you redirect: [code]$this->clear_page_cache($newURI); $this->session->flashdata('logout','Laters!'); redirect($newURI);[/code]
[code]<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
-
Cache file naming routine factored out to allow for manual deletion.
-
Responsible for sending final output to browser
-
@package CodeIgniter
-
@subpackage Libraries
-
@hacked-by Bradford Mar */ class MY_Output extends CI_Output {
/**
- Get the uri of a given cached page
- @access public
- @return
*/
function get_cache_URI($set_uri = null){ $CFG =& load_class('Config'); $URI =& load_class('URI');
$set_uri = (isset($set_uri)) ? $set_uri : $URI->uri_string; $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); if ( ! is_dir($cache_path) OR ! is_writable($cache_path)) { return FALSE; } /* * Build the file path. The file name is an MD5 hash of the full URI */ $uri = $CFG->item('base_url'). $CFG->item('index_page'). $set_uri; return array('path'=>$cache_path, 'uri'=>$uri);}
// --------------------------------------------------------------------
/**
- Manually clear a cached file
- @access public
- @return void */
function clear_page_cache($set_uri = null, $filepath = null){ switch (isset($filepath)) { case FALSE: $cacheuri = $this->get_cache_URI($set_uri); $filepath = $cacheuri['path']; $filepath .= md5($cacheuri['uri']);
default: if(file_exists($filepath)) { touch($filepath); unlink($filepath); log_message('debug', "Cache deleted for: ".$cacheuri['uri']); } else { return FALSE; } break; } } } // END MY_Output Class
/* End of file MY_Output.php / / Location: ./system/application/libraries/MY_Output.php */[/code]