Welcome Guest, Not a member yet? Register   Sign In
Cacheing not working
#1

[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-gui...mple_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.
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB