How is clear page cache in the CodeIgniter

2019-03-28 15:24发布

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

How can clear page cache in the CodeIgniter?

5条回答
孤傲高冷的网名
2楼-- · 2019-03-28 16:00
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);       
}
查看更多
Viruses.
3楼-- · 2019-03-28 16:05

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

查看更多
劫难
4楼-- · 2019-03-28 16:15

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

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

查看更多
欢心
5楼-- · 2019-03-28 16:18

You can use this simple plugin to help clear the cache for individual pages.

Link to a codeigniter class

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-03-28 16:24
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);
}
查看更多
登录 后发表回答