Welcome Guest, Not a member yet? Register   Sign In
Caching not working! Blank page. How does CI write a cache file? All I see is a timestamp.
#1

[eluser]dtrenz[/eluser]
Is that what it is supposed to look like?

in my cache dir is a file with the following contents: "1203013622TS--->"

That's it. Is that right? I'm guessing something is wrong, since the page I am caching is blank after it get's cached.

I am placing the cache code as the first line in my controller index() function:
Code:
$this->output->cache(60);

Any help appreciated. I'm pretty new to CI and very new to caching w/ CI. Thanks -d
#2

[eluser]nirbhab[/eluser]
Have a look over the user guide containing following lines.

Warning: Because of the way CodeIgniter stores content for output, caching will only work if you are generating display for your controller with a view.

Note: Before the cache files can be written you must set the file permissions on your system/cache folder such that it is writable.

i hope you are accessing the controller not the cache file directly.

Add your code, so that i could run and solve the problem.
#3

[eluser]dtrenz[/eluser]
Yes, I read what little documentation there is very carefully.

Like I said, I am placing the cache code as the first line in my controller index() function. And when I load a cached page/controller, I get a blank page.

Here is a stripped down version of my code (note: this is my default controller):

Code:
class Home extends Controller
{
    public function __construct()
    {
        parent::Controller();
    }
    
    public function index()
    {
        $this->output->cache(60);

        $this->load->helper('text');
        $this->load->helper('html');
        $this->load->model('home_model');
    
        $data['heading'] = "Welcome to the homepage!";
        
        $this->load->view('home_view.php', $data);
    }
}
#4

[eluser]nirbhab[/eluser]
Hi, i ran your script by commenting
Code:
$this->load->model('home_model');
, and surprise to you, it ran very well, with cache in system/cache/, please do one thing, enable error reporting from php.ini file, so that if any error is there you will get it solved.
#5

[eluser]dtrenz[/eluser]
well... unless you have my home model file, it won't work. that should be obvious. I have error reporting on and I still only get a blank page.
#6

[eluser]dtrenz[/eluser]
OK, I just walked the CI Output class and I can't find anywhere that they are writing the actual output of the page to the cache file!

All it does is write a timestamp to a file. Where is the actual output? Where is the content and the HTML? I'm so confused. could somebody please explain this to me

Code:
if ( ! $fp = @fopen($cache_path, 'wb'))
{
    log_message('error', "Unable to write cache file: ".$cache_path);
    return;
}

$expire = time() + ($this->cache_expiration * 60);

flock($fp, LOCK_EX);
fwrite($fp, $expire.'TS--->'.$output);
flock($fp, LOCK_UN);
fclose($fp);
#7

[eluser]dtrenz[/eluser]
I figured it out!

I was using output buffering on all my pages (ob_start()Wink and that was keeping the final output from being written to the cache.

Does CI support output buffering?
#8

[eluser]gzhao[/eluser]
I'm running into a similar problem. any more progress on this?
#9

[eluser]gzhao[/eluser]
i also have the same problem and traced the issue to libraries/Loader.php,
in the last part of: function _ci_load($_ci_data)

the $OUT->final_output (libraries/Output.php) variable wasn't getting populated.
my fix is to take the calls to set the output variable out of the conditional statements.
it didn't seem to have broken anything on the test site but more thorough testing is needed.


ORIGINAL
Code:
if (ob_get_level() > $this->_ci_ob_level + 1)
{        
    ob_end_flush();
}
else
{
    // PHP 4 requires that we use a global
    global $OUT;
    $OUT->append_output(ob_get_contents());
    @ob_end_clean();
}

FIXED

Code:
// PHP 4 requires that we use a global
global $OUT;
$OUT->append_output(ob_get_contents());
@ob_end_clean();

// ORIGINAL CODE
/*
if (ob_get_level() > $this->_ci_ob_level + 1)
{        
    ob_end_flush();
}
else
{
    // PHP 4 requires that we use a global
    global $OUT;
    $OUT->append_output(ob_get_contents());
    @ob_end_clean();
}
*/




Theme © iAndrew 2016 - Forum software by © MyBB