到目前为止,我正在尝试学习Codeigniter并了解基础知识,但在我尝试测试时,似乎缓存正在阻碍。通常,当我在localhost上测试时,我做了一个更改并立即在浏览器中看到它,但是使用Codeigniter,似乎我需要等待~1分钟才能在浏览器中看到更改。有没有办法普遍禁用Codeigniter缓存,以便在发生变化时立即发生?
答案 0 :(得分:9)
将此代码放在controller
的__construct函数中$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
$this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
答案 1 :(得分:0)
只需删除application / cache文件夹中的所有缓存项目:
http://ellislab.com/codeigniter/user-guide/general/caching.html
答案 2 :(得分:0)
IF 您启用了缓存,您需要将其禁用(注释掉缓存)。 否则它可能是您的浏览器缓存,您可以强制SHIFT-F5(在大多数浏览器中)。
只有在控制器等中定义了缓存,缓存才会起作用;不是随意的。
答案 3 :(得分:0)
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class MY_Cacheoff extends CI_Cacheoff {
/**
* author: https://www.blazingcoders.com
*/
function disable_cache() {
$this->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$this->set_header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$this->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
$this->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
$this->set_header('Pragma: no-cache');
}
}
有关详细说明,请检查链接