我正在学习Codeigniter,并且目前已经理解了基础知识,但在测试时似乎缓存会影响。通常情况下,在本地主机上测试时,我进行更改后可以立即在浏览器中看到它,但是使用Codeigniter时,更改需要等待大约1分钟才能在浏览器中看到。是否有一种方法可以普遍禁用Codeigniter缓存,以便在开发过程中更改会立即生效?
我正在学习Codeigniter,并且目前已经理解了基础知识,但在测试时似乎缓存会影响。通常情况下,在本地主机上测试时,我进行更改后可以立即在浏览器中看到它,但是使用Codeigniter时,更改需要等待大约1分钟才能在浏览器中看到。是否有一种方法可以普遍禁用Codeigniter缓存,以便在开发过程中更改会立即生效?
只需将此代码放入控制器的__construct函数中即可。
$this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
$this->output->set_header('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");
只需删除应用程序/缓存文件夹中的所有缓存项目:
http://ellislab.com/codeigniter/user-guide/general/caching.html
如果您启用了缓存,您需要禁用它(注释掉缓存)。 否则可能是您的浏览器缓存,您可以在大多数浏览器中强制使用SHIFT-F5。
只有在控制器等中定义了缓存,它才会起作用;而不是随机的。
<?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');
}
}
详细解释请查看链接
$this->output->set_header
出现了问题。 - TARKUS