CodeIgniter Forums
Cacheing not working - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter Archived (from EllisLab) (
+--- Forum: Archived Development & Programming (
+--- Thread: Cacheing not working (/thread-40918.html)

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

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

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:

$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);

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

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

Lines 160-171 shown below:
$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.