Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is clear page cache in the CodeIgniter

I use CodeIgniter. Always part of my page is cache and don't remove by Ctrl+F5 in the browser. When I change the name page in the view it worked !!!?

How can clear page cache in the CodeIgniter?

like image 615
Jennifer Anthony Avatar asked Sep 14 '11 19:09

Jennifer Anthony


3 Answers

You need to manually delete the cached items in the application/cache folder.

https://www.codeigniter.com/user_guide/general/caching.html

like image 57
birderic Avatar answered Nov 12 '22 14:11

birderic


function delete_cache($uri_string=null)
{
    $CI =& get_instance();
    $path = $CI->config->item('cache_path');
    $path = rtrim($path, DIRECTORY_SEPARATOR);

    $cache_path = ($path == '') ? APPPATH.'cache/' : $path;

    $uri =  $CI->config->item('base_url').
            $CI->config->item('index_page').
            $uri_string;

    $cache_path .= md5($uri);

    return unlink($cache_path);
}
like image 38
cesarve Avatar answered Nov 12 '22 12:11

cesarve


public function clear_path_cache($uri)
{
    $CI =& get_instance();
    $path = $CI->config->item('cache_path');
    //path of cache directory
    $cache_path = ($path == '') ? APPPATH.'cache/' : $path;

    $uri =  $CI->config->item('base_url').
    $CI->config->item('index_page').
    $uri;
    $cache_path .= md5($uri);

    return @unlink($cache_path);
}




/**
 * Clears all cache from the cache directory
 */
public function clear_all_cache()
{
    $CI =& get_instance();
    $path = $CI->config->item('cache_path');

    $cache_path = ($path == '') ? APPPATH.'cache/' : $path;

    $handle = opendir($cache_path);
    while (($file = readdir($handle))!== FALSE) 
    {
        //Leave the directory protection alone
        if ($file != '.htaccess' && $file != 'index.html')
        {
           @unlink($cache_path.'/'.$file);
        }
    }
    closedir($handle);       
}
like image 37
Tarek Sumch Avatar answered Nov 12 '22 14:11

Tarek Sumch