Welcome Guest, Not a member yet? Register   Sign In
Bypass output cache when logged in
#1

[eluser]deadelvis[/eluser]
Hi Everyone... quick question, hope someone can give me some pointers on where to look.

Is it possible to show a "rendered" version of the page instead of the output cached one when (for instance) a user is logged in? Is there a way to simply bypass the cache and show a "live" version?

I am having a bit of trouble figuring out if this is possible in some simple form with CI.

Cheers
#2

[eluser]deadelvis[/eluser]
Answering my own question here... this seems to do the trick:

Code:
<?php
class MY_Output extends CI_Output {
    
    function _display_cache(&$CFG, &$URI) {
        session_start();
        if (@$_SESSION["some_var"]==true){
            return false;
        } else {
            return parent::_display_cache(&$CFG, &$URI);
        }
    }

    function _write_cache($output){
        if (@$_SESSION["some_var"]==true){
            return;
        } else {
            return parent::_write_cache($output);
        }
    }
}
?>

File cache is not read or written to, as long as that native PHP session variable is true.

I know this approach might not be very pretty but it is probably the simplest solution to completely bypass CI's file caching when this is necessary for a single condition (Example: Displaying admin links together with regular content when admin is logged in).




Theme © iAndrew 2016 - Forum software by © MyBB