CodeIgniter Forums
Cacheing not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Cacheing not working (/showthread.php?tid=40918)



Cacheing not working - El Forum - 04-22-2011

[eluser]dfreerksen[/eluser]
I'm playing with the new Cache drivers in Codeigniter and I'm having some troubles. I downloaded the latest code from Codeigniter Reactor. I am using the exact same sample cache code found in the User Guide at http://ellislab.com/codeigniter/user-guide/libraries/caching.html#example_usage

I have verified both APC is supported and my application/cache/ directory is writable. The problem is, it never caches. If i do var_dump($this->cache->get_metadata('foo')); it returns false. Meaning it used the dummy cache.

If I do something like this everything works just fine:

$this->load->driver('cache');
$driver = 'file';
if ($this->cache->apc->is_supported())
{
$driver = 'apc';
}
if ( ! $foo = $this->cache->{$driver}->get('foo'))
{
echo 'Saving to the cache!<br />';
$foo = 'foobarbaz!';
$this->cache->{$driver}->save('foo', $foo, 300);
}
var_dump($this->cache->get_metadata('foo'));

Am I missing something or doing something wrong? Is this a bug in the CI code? If this is a bug, does anyone have any idea how to fix this? I've been looking through the Cache code and haven't been able to find any issues yet.


Cacheing not working - El Forum - 07-08-2011

[eluser]Unknown[/eluser]
Line 160 in /system/libraries/Cache/drivers/Cache_file.php looks like it's the problem:

Lines 160-171 shown below:
Code:
$data = $data['data'];
            $mtime = filemtime($this->_cache_path.$id);

            if ( ! isset($data['ttl']))
            {
                return FALSE;
            }

            return array(
                'expire'     => $mtime + $data['ttl'],
                'mtime'        => $mtime
            );

If I do a print_r of $data, it contains ['ttl']. However assigning $data = $data['data'] does not work here, as it loses the metadata. So the function can never return the array.

Line 160 should be removed / commented out, and then it'll work.