Welcome Guest, Not a member yet? Register   Sign In
Caching in custom database group.
#1

[eluser]kamilko[/eluser]
Hi.
I have following case:
database config group called 'configuration' and of course an 'default' group.
I'm trying to load database 'configuration' without loading 'default' database in library which is loaded in controller constructor.
so my library constructor looks like this:
Code:
function __construct() {
    $this->obj =& get_instance();
    $this->db = $this->obj->load->database('configuration', TRUE);
}

my part of configuration group looks like:
Code:
$db['configuration']['cache_on'] = TRUE;
$db['configuration']['cachedir'] = "/tmp";

and when I trying load my library I have following error:
Quote:Fatal error: Call to a member function cache_off() on a non-object in ...system/database/DB_cache.php on line 58

Obviously '/tmp' dir has access for httpd process and it doesn't matter if I use 'mysql' or 'mysqli' driver.

If I place in constructor before loading 'configuration' group following code:
Code:
$this->obj->load->database();
Error is gone - but I'm not sure if then I have cached 'configuration' group instead of only group 'default'.
#2

[eluser]Seppo[/eluser]
I think cache will only work with the database object assigned to $CI->db. I don't find any note about this in the documentation, and I think this can be easily corrected...
On the _cache_init method the Cache object is instantiated (line 1086)... you can pass the database instance to the constructor and replacing the $this->CI->db call for $this->db... something like this

database/DB_driver.php - line 1086
Code:
$this->CACHE = new CI_DB_Cache;
//replaced by
$this->CACHE = new CI_DB_Cache($this);

database/DB_cache.php
Code:
class CI_DB_Cache {

    var $CI;
    var $db;

    /**
     * Constructor
     *
     * Grabs the CI super object instance so we can access it.
     *
     */    
    function CI_DB_Cache(&$db)
    {
        // Assign the main CI object to $this->CI
        // and load the file helper since we use it a lot
        $this->CI =& get_instance();
        $this->db =& $db;
        $this->CI->load->helper('file');    
    }

    // --------------------------------------------------------------------
and then, on the same file, search & replace all $this->CI->db for $this->db

I've tested it here and it seems to work =)
#3

[eluser]kamilko[/eluser]
Thank you!

I think this should be included in next CI realease.




Theme © iAndrew 2016 - Forum software by © MyBB