How is clear page cache in the CodeIgniter

前端 未结 4 1729
深忆病人
深忆病人 2021-02-09 08:02

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

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-09 08:18

    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);       
    }
    

提交回复
热议问题