8

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?

4 Answers 4

12

Just put this code in the __construct function of controller

$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");
Sign up to request clarification or add additional context in comments.

2 Comments

There's something broken on the fifth line of your example code, $this->output->set_header
Is this supposed to appear in the generated HTML file? Because I tried putting this in the view controller's constructor and those new headers did not appear in the generated HTML file :-/ Did I miss a step here?
0

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

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

Comments

0

IF you 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).

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

1 Comment

AFAIK, i have used Ctrl+F5 or Command+R for overriding the browser cache while refreshing, Shift+f5 looks strange..simply it doesn't works
0
<?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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.