Search code examples
phpcodeignitercachingapcfatal-error

CodeIgniter cache driver ignoring backup adapter


I'm trying to use the cache driver which CodeIgniter supplies in their PHP framework. However, it seems to fully ignore the backup adapter.

If I use:

$this->load->driver('cache', array('adapter' => 'apc', 'backup' => 'dummy'));

Then I assume that it will use APC if available, otherwise it'll fall back to dummy cache (do nothing). This is obviously very handy since not everyone will have APC installed.

This doesn't seem to be the case - since I get an error when testing the following code:

if(!$config = $this->cache->get('config')) {

    //Get config from database
    $config = $this->db->from('core')->get()->row_array();

    //Cache it
    $this->cache->save('config', $config, 600); 
}

(Fatal error: Call to undefined function apc_cache_info())


Solution

  • There are two active pull requests on the GitHub Issue Tracker which pertain to this problem:

    https://github.com/EllisLab/CodeIgniter/pull/661

    https://github.com/EllisLab/CodeIgniter/pull/1403

    They are both a little different and while one of them looks pretty old (I didn't notice it) the second more recent issue might be right up your alley.

    If you can verify either of the fixes then give the pull request a +1 and I'll merge it.

    I had an issue a while back where I wanted to use Memcache on a server which didn't have it installed correctly, and instead of it falling back to Files it just bitched at me, but I never found the time to fix it. If this is the same issue then great, I can get it merged.