From b37d2bc462af918276111d0439592aa445ac6277 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Nov 2012 02:19:35 +0200 Subject: Add CI_Output::delete_cache() (an improved version of PR #609) --- system/core/Output.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'system/core/Output.php') diff --git a/system/core/Output.php b/system/core/Output.php index 7bfde07c7..98deff55c 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -626,6 +626,45 @@ class CI_Output { // -------------------------------------------------------------------- + /** + * Delete cache + * + * @param string $uri URI string + * @return bool + */ + public function delete_cache($uri = '') + { + $CI =& get_instance(); + $cache_path = $CI->config->item('cache_path'); + if ($cache_path === '') + { + $cache_path = APPPATH.'cache/'; + } + + if ( ! is_dir($cache_path)) + { + log_message('error', 'Unable to find cache path: '.$cache_path); + return FALSE; + } + + if (empty($uri)) + { + $uri = $CI->uri->uri_string(); + } + + $cache_path .= md5($CI->config->item('base_url').$CI->config->item('index_page').$uri); + + if ( ! @unlink($cache_path)) + { + log_message('error', 'Unable to delete cache file for '.$uri); + return FALSE; + } + + return TRUE; + } + + // -------------------------------------------------------------------- + /** * Set Cache Header * -- cgit v1.2.3-24-g4f1b