How is clear page cache in the CodeIgniter
Asked Answered
O

5

8

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?

Ordure answered 14/9, 2011 at 19:37 Comment(0)
V
10

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

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

Vexillum answered 14/9, 2011 at 20:26 Comment(1)
codeigniter.com/user_guide/general/caching.html is the current 3.x link....Interlining
A
4
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);
}
Alexia answered 22/7, 2013 at 23:28 Comment(1)
This answer is missing its educational explanation.Coon
V
4
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);       
}
Volitive answered 14/8, 2015 at 5:5 Comment(1)
This answer is missing its educational explanation.Coon
B
0

Codeigniter 3

I added an endpoint to a controller

function delete_cache() {
    preg_match("/(\/index.php)(?<endpoint>\/[\w.-\/]*)/", 
    $_SERVER["HTTP_REFERER"], $result);
    $this->output->delete_cache($result["endpoint"]);
    redirect($result["endpoint"]);
}

Then I added a refresh button pointed to this endpoint. When the user click on the refresh button the current cached file will be delete, then redirect to the page.

Berns answered 16/5, 2023 at 15:2 Comment(1)
Is that regex pattern really intending to include a range of characters from a literal dot to a forward slash?Coon
S
-6

It is probably in a session.Try deleting your cookies.

Sheasheaf answered 14/9, 2011 at 19:39 Comment(2)
i deleting the cookies in the chrome browser but not ok.Ordure
its saved server side, as described there: codeigniter.com/user_guide/general/caching.htmlLogistician

© 2022 - 2024 — McMap. All rights reserved.