php Codeigniter 禁用缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19775382/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:00:22  来源:igfitidea点击:

Codeigniter Disable Cache

phpcodeignitercaching

提问by kaarch

I'm trying to learn Codeigniter and understand the basics so far, but as I try to test, it seems the cache is getting in the way. Normally when I test on localhost I make a change and instantly can see it in browser, but with Codeigniter it seems I have to wait ~1 minute for changes to be seen in browser. Is there a way to universally disable the Codeigniter cache so when developing changes happen immediately?

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

回答by Vivex

Just put this code in the __construct function of controller

只需将这段代码放在控制器的 __construct 函数中

$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");

回答by Hackerman

Just delete all the cached items in the application/cache folder:

只需删除 application/cache 文件夹中的所有缓存项目:

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

回答by Jakub

IFyou enabled the cache, you need to disable it (comment out the cache). Otherwise it may be your browser caching, you could force a SHIFT-F5 (in most browsers).

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

The cache will only work if you have it so defined in your controller etc; not randomly.

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

回答by vivek kumar

<?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');
        }

    }

For Detail Explanation check the link

有关详细说明,请查看链接

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

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