• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Caching does not work

#1
[eluser]Unknown[/eluser]
I load the driver in the constructor:

Code:
public function __construct()
    {
        parent::__construct();
        $this->load->driver('cache');    
    }

I call savetocache:

Code:
public function savetocache()
    {
    
        if ( ! $foo = $this->cache->get('foo'))
        {
             echo 'Saving to the cache!<br />';
             $foo = 'foobarbaz!';

             $this->cache->file->save('foo', $foo, 300);

        }

        echo $foo;    
    }

Output (even if I refresh):

Code:
Saving to the cache!
foobarbaz!

I call testcache:

Code:
public function testcache(){
    
    var_dump($this->cache->get_metadata('foo'));

$foo = $this->cache->get('foo');
    
    echo $foo;
    
    }

Output:

Code:
bool(false)
I go to [app dir]/cache (CHMOD'd 777) and I see a file called "foo", output:

Code:
a:3:{s:4:"time";i:1302827920;s:3:"ttl";i:300;s:4:"data";s:10:"foobarbaz!";}

I'm running Code Igniter 2.0.2 with the following modification:

Quote:Fixed Smile
./system/libraries/Driver.php
from
$filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.EXT;
to
$filepath = $path.'libraries/'.ucfirst($lib_name).'/drivers/'.$class.EXT;

Source: https://bitbucket.org/ellislab/codeignit...cache_file

Please help Sad

#2
[eluser]bubbafoley[/eluser]
try this

Code:
public function __construct()
    {
        parent::__construct();
        $this->load->driver('cache', array('adapter'=>'file'));    
    }

This way you are telling the Cache driver library to use the file adapter by default.

then your function looks like this

Code:
public function savetocache()
    {
    
        if ( ! $foo = $this->cache->get('foo'))
        {
             echo 'Saving to the cache!<br />';
             $foo = 'foobarbaz!';

             $this->cache->save('foo', $foo, 300);

        }

        echo $foo;    
    }

The way you have it now you are using the file adapter to save the cache but not to retrieve it.


If you don't pass a default adapter when loading the driver, you have to specify which adapter to use each time.

Code:
$this->load->driver('cache'); // using dummy cache by default
$this->cache->file->get('foo');
$this->cache->file->save('foo', $foo);


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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