如何在CodeIgniter中清除页面缓存


How is clear page cache in the CodeIgniter

我使用CodeIgniter。总是我的页面的一部分是缓存,不删除Ctrl+F5在浏览器中。当我在视图中更改名称页时,它工作了!

如何在CodeIgniter中清除页面缓存?

您需要手动删除application/cache文件夹中的缓存项。

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

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

Codeigniter 3

我给控制器添加了一个端点

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

然后我添加了一个指向这个端点的刷新按钮。当用户点击刷新按钮时,当前缓存的文件将被删除,然后重定向到该页。

这可能是在session .尝试删除您的cookies