[英]CodeIgniter: how to globally disable caching?
My clients's website is done with CodeIgniter.我客户的网站是用 CodeIgniter 完成的。 Problem is: any time I make some changes, I need to empty the 'cache' folder.
问题是:每当我进行一些更改时,我都需要清空“缓存”文件夹。
I know you can disable cache in a controller:我知道您可以在控制器中禁用缓存:
$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
But how to disable it Globally to the WHOLE website ?但是如何在整个网站上全局禁用它?
you can globally disable whole website cache by using htaccess您可以使用 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>
Create the file /application/core/My-Output.php that has the following lines:创建具有以下几行的文件/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);
}
This will override the global output handler in your CodeIgniter application in any way you desire.这将以您想要的任何方式覆盖 CodeIgniter 应用程序中的全局输出处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.