cnandreu
cnandreu

Reputation: 5111

Help with caching on codeigniter 2

Code and error output: https://i.sstatic.net/S0W3m.png

“An Error Was Encountered Unable to load the requested driver: CI_Cache_apc”

Reference: http://codeigniter.com/user_guide/libraries/caching.html

Notes: Using CI 2.0.2 app/cache and system/libraries/Cache are recursively (files and folders) CHMOD’d 777. The lib one was just for testing if that fixed the problem, it did not.

Thanks!

Upvotes: 1

Views: 6503

Answers (3)

Amol Gholap
Amol Gholap

Reputation: 111

If your CI is old then replace system/libraries/drivers.php from latest CodeIgniter bundle

If your CI is old then replace system/Cache/ folder from latest CodeIgniter bundle

Add cache path in config.php

then run the

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

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

            // Save into the cache for 5 minutes
            $this->cache->save('foo', $foo, 300);
    }

    echo $foo;

Now my caching is working

Upvotes: 1

Gaurang Jadia
Gaurang Jadia

Reputation: 1516

I was using CodeIgniter V 2.0.2 and had the same exception for few days. I just updated my framework to CodeIgniter V 2.0.3. It is working good with APC.

Visit my friends blog testing hosted on my VPS. Here is Blog Link. Also, Take a look at the cache entries on his Virtual Host at http://www.dhavalpatels.com/apc.php

Here is the code

<?php

class Blog extends CI_Controller {

    function Blog() {
        parent::__construct();
    }

    public function index() {
        $data['title'] = "My Blog | DhavalPatels.com";
        $data['head'] = "My ToDo";
        $data['todo'] = array('Go to BestBuy', 'Dinner', 'Call mom');

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

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

                // Save into the cache for 5 minutes
                $this->cache->save('foo', $foo, 300);
        }

        echo $foo;

        $this->load->view('blog_view', $data);
    }
}
?>

Upvotes: 6

Carlos Mora
Carlos Mora

Reputation: 1184

despite the doc, try using

'adapter' => 'cache_apc' 

in place of

'adapter' => 'apc'

Can you check if apc is supported using is_supported($driver)?

Upvotes: 0

Related Questions