我的客户的网站是使用CodeIgniter完成的。 问题是:每次我做一些更改,我都需要清空'cache'文件夹。
我知道您可以在控制器中禁用缓存:
$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");
$this->output->set_header
但是如何在全球网站上禁用它?
答案 0 :(得分:3)
您可以使用htaccess
全局禁用整个网站缓存<FilesMatch "\.(html|htm|js|css|php)>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</FilesMatch>
答案 1 :(得分:0)
创建具有以下行的文件 /application/core/My-Output.php :
class MY_Output extends CI_Output {
function _display_cache(&$CFG, &$URI)
{
/* Disable Globally */
return FALSE;
/* OR - Disable for a specific IP Address */
if ( ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') || (eregi("192.168.", $_SERVER['REMOTE_ADDR'])) )
{
return FALSE;
}
/* OR - disable based on a cookie value */
if ( (isset($_COOKIE['nocache'])) && ( $_COOKIE['nocache'] > 0 ) )
{
return FALSE;
}
/* Call the parent function */
return parent::_display_cache($CFG,$URI);
}
这将以您想要的任何方式覆盖CodeIgniter应用程序中的全局输出处理程序。