【问题标题】:Codeigniter Disable CacheCodeigniter 禁用缓存
【发布时间】:2013-11-15 12:34:16
【问题描述】:

到目前为止,我正在尝试学习 Codeigniter 并了解基础知识,但是当我尝试进行测试时,缓存似乎妨碍了我。通常,当我在 localhost 上进行测试时,我会进行更改并立即在浏览器中看到它,但是使用 Codeigniter 似乎我必须等待大约 1 分钟才能在浏览器中看到更改。有没有办法普遍禁用 Codeigniter 缓存,以便在开发更改时立即发生?

【问题讨论】:

    标签: php codeigniter caching


    【解决方案1】:

    只要把这段代码放在控制器的__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");
    

    【讨论】:

    • 感谢出色的解决方案 :)
    • 示例代码的第五行有问题,$this->output->set_header
    • 这应该出现在生成的 HTML 文件中吗?因为我尝试将它放在视图控制器的构造函数中,而那些新的标头没有出现在生成的 HTML 文件中:-/我在这里错过了一步吗?
    【解决方案2】:

    只需删除应用程序/缓存文件夹中的所有缓存项:

    http://ellislab.com/codeigniter/user-guide/general/caching.html
    

    【讨论】:

      【解决方案3】:

      如果你启用了缓存,你需要禁用它(注释掉缓存)。 否则可能是您的浏览器缓存,您可以强制使用 SHIFT-F5(在大多数浏览器中)。

      只有在控制器等中定义了缓存时,缓存才会起作用;不是随机的。

      【讨论】:

      • AFAIK,我使用 Ctrl+F5 或 Command+R 在刷新时覆盖浏览器缓存,Shift+f5 看起来很奇怪..只是它不起作用
      【解决方案4】:
      <?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');
              }
      
          }
      

      详细解释请查看链接

      https://www.blazingcoders.com/how-to-disable-browser-cache-easily-for-particular-individual-and-separate-function-and-controller-in-codeigniter

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-23
        • 2016-01-04
        • 1970-01-01
        • 1970-01-01
        • 2017-07-13
        • 1970-01-01
        • 2011-03-11
        • 2014-08-12
        相关资源
        最近更新 更多