8

I'm unable to configure database cache to my system. I've tried every configuration that available in internet . please help me out.

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '123',
'database' => 'test',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => TRUE,
'cachedir' => 'application/cache',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt'  => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
    'save_queries' => TRUE
);

Below is the error message that i'm getting

An uncaught Exception was encountered

Type: Exception

Message: Configured database connection has cache enabled. Aborting.

Filename: C:\wamp\www\test\system\libraries\Session\drivers\Session_database_driver.php

1
  • its not working I tried as you said. do i have to make any changes in Session_database_driver.php ? Commented Aug 29, 2016 at 10:55

2 Answers 2

8

Caching is enabled in three steps:

1) Create a writable directory on your server where the cache files can be stored.

2) Set the path to your cache folder in your application/config/database.php file. For Example :

$db['default']['hostname'] = 'XXXXX';
$db['default']['username'] = 'XXXXX';
$db['default']['password'] = 'XXXXX';
$db['default']['database'] = 'XXXXX';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = 'XXX';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = TRUE;
$db['default']['cachedir'] = 'application/cache';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

3) Enable the caching feature, either globally by setting the preference in your application/config/database.php file, or Manually enables/disables caching as described below.

 // Turn caching on
 $this->db->cache_on();

 // Turn caching off for this one query
 $this->db->cache_off();

Also, make sure your directory is writable (if you are on Mac or Linux)

sudo chmod 777 -R application/cache

I hope it will work for you.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't believe 777 is he best choice, maybe 755 it's safer.
Awesome, the cache worked and started to store the cache in the cache directory. Thank you
0

I have to modify the db_cache class as follows

vi +146 /var/www/html/sys/database/DB_cache.php

//ekariz

if(!is_readable($filepath)){
    return FALSE;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.