• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Corrupt cache files?

#1
[eluser]座頭市[/eluser]
I have an odd problem which I can't figure out:

I have a site which uses CI caching extensively. Over the past few days, some URLs have been impossible to open: the connection is made but then everything just hangs. After talking to tech support to make sure nothing had changed on the server, it was pointed out to me that it was only certain pages which were not loading (in this case, my top page), but only at the root. For example, these two URLs load the top page:
Code:
http://www.foo.com/
http://www.foo.com/main/index
The former hangs, the latter opens the page with no problem. After tearing my hair out (what little hair I have, that is) for a while, in desperation I deleted the cache and everything went back to normal. Okay, corrupt cache file. Fine. But recently I've noticed the problem again on a few pages. So, I took a look inside the cache to find a few pages which were either blank (OB) or tiny (16B). The blank files obviously contained nothing, the other files started off normally, they had the page hash (i.e. 1190432279TS---&gtWink but nothing following it. I deleted the files, tried reloading, but the URLs were still hanging. I deleted all the cache files again and things were back to normal. I'm just happy that this is my hobby site and not anything that I've done for a client!

Has anyone encountered anything like this? This particular site is being hosted with Dreamhost if that rings a bell for anyone.

#2
[eluser]losjackal[/eluser]
I concur...I'm testing caching on fresh installations of CodeIgniter, and I'm only ending up with a 16 byte file that appears to have the timestamp and nothing else. As a result, viewing the the page the first time is fine, but the second and subsequent times you are served a blank page until the cache expires.

I've tested this in two installations on a FreeBSD server, and also on my local Mac OS X installation.

My test is, I've added a function to the Welcome controller:
Code:
function dbtest()
    {
        $this->load->database();
        $this->output->cache(1);
        
        $query = $this->db->get('people');

        foreach ($query->result() as $row)
        {
            echo "$row->name<br/>\n";
        }
    }
The system/cache directory is writeable, because CI generates the following file:
Code:
-rwxrwxrwx    1 www     carlos   16 Oct  2 06:37 6ac77f2fe15ba7dc8c275a0478b62f46
with contents like:
Code:
1191325117TS---&gt;

#3
[eluser]Derek Allard[/eluser]
Yikes! Confirmed.

I'm moving this to the bug report forum. I probably won't have time to get to it for at least several days, so if you wanted to accelerate things I'd certainly appreciate debugging help.

Code:
function cachetest()
{
    $this->output->cache(1);
    echo 'foo';
}

#4
[eluser]Derek Allard[/eluser]
OK, got it (man that was a lot of code tracing). Turns out it was something dumb. Because of the way content is buffered for output, the cache can only be used if you are generating content with a view. Thus:

Code:
function cachetest()
{
    $this->output->cache(1);
    echo 'foo';
}
won't work, but
function cachetest()
{
$this->output->cache(1);
$this->load->view('foo');
}
[/code]
will.

I'll make a note in the userguide to this effect.

#5
[eluser]losjackal[/eluser]
Thanks, Derek. No wonder it mostly went unnoticed...most people use views!

In testing further, it appears only View-generated content can be cached. I think that's what you've stated above, but it might be worthwhile pointing out in the user guide correction that even if you call the view as you show above, any echo statements in the controller still won't be part of the cache. (In a certain light, that's actually a feature!)

And finally for the record, I don't think this revelation helps the original poster above quite yet. Sad

#6
[eluser]Armchair Samurai[/eluser]
I'm glad that the bug was squashed, but I think that my problem might have been a little different: when you mentioned the echo thing, I went back and checked my code to make sure, but I have no echo statements anywhere in my controllers, so it might be a different issue?

My front page controller is about as simple as it can be:
Code:
function index()
{
    $this->output->cache(5);
    
    $this->load->view('top');
}
In anycase, whatever was causing the problem seems to have stopped for the moment, but I'll keep an eye out if it happens again and run some tests.

And I agree with losjackal - the non-caching echo could be considered a feature, as long as you're not an MVC-Nazi and can handle an echo statement or two in the controller.... Wink

(Yes, I'm the original poster but I'm having some issues with my original account at the moment.)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.