【问题标题】:CodeIgniter: how to globally disable caching?CodeIgniter:如何全局禁用缓存?
【发布时间】:2016-05-18 13:50:04
【问题描述】:

我客户的网站是用 CodeIgniter 完成的。 问题是:每当我进行一些更改时,我都需要清空“缓存”文件夹。

我知道你可以在控制器中禁用缓存:

 $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

但是如何在全球范围内禁用它到整个网站?

【问题讨论】:

标签: php codeigniter caching codeigniter-2 cache-control


【解决方案1】:

您可以使用 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>

【讨论】:

  • 不应该是&lt;FilesMatch "\.(html|htm|js|css|php)$&gt;(包括$)吗?
【解决方案2】:

创建具有以下行的文件 /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 应用程序中的全局输出处理程序。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-15
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 2016-01-04
    • 1970-01-01
    • 2011-02-09
    相关资源
    最近更新 更多