passed db object by reference to DB Cache class, and changed the cache class to use that db object instead of $CI->db, to support returned db objects and multiple db connections
http://codeigniter.com/bug_tracker/bug/4223/
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php
index 21113af..448727f 100644
--- a/system/database/DB_cache.php
+++ b/system/database/DB_cache.php
@@ -25,6 +25,7 @@
class CI_DB_Cache {
var $CI;
+ var $db; // allows passing of db object so that multiple database connections and returned db objects can be supported
/**
* Constructor
@@ -32,11 +33,12 @@
* Grabs the CI super object instance so we can access it.
*
*/
- function CI_DB_Cache()
+ 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');
}
@@ -53,12 +55,12 @@
{
if ($path == '')
{
- if ($this->CI->db->cachedir == '')
+ if ($this->db->cachedir == '')
{
- return $this->CI->db->cache_off();
+ return $this->db->cache_off();
}
- $path = $this->CI->db->cachedir;
+ $path = $this->db->cachedir;
}
// Add a trailing slash to the path if needed
@@ -67,10 +69,10 @@
if (! is_dir($path) OR ! is_really_writable($path))
{
// If the path is wrong we'll turn off caching
- return $this->CI->db->cache_off();
+ return $this->db->cache_off();
}
- $this->CI->db->cachedir = $path;
+ $this->db->cachedir = $path;
return TRUE;
}
@@ -89,7 +91,7 @@
{
if (! $this->check_path())
{
- return $this->CI->db->cache_off();
+ return $this->db->cache_off();
}
$uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+';
@@ -97,7 +99,7 @@
$filepath = $uri.'/'.md5($sql);
- if (FALSE === ($cachedata = read_file($this->CI->db->cachedir.$filepath)))
+ if (FALSE === ($cachedata = read_file($this->db->cachedir.$filepath)))
{
return FALSE;
}
@@ -117,13 +119,13 @@
{
if (! $this->check_path())
{
- return $this->CI->db->cache_off();
+ return $this->db->cache_off();
}
$uri = ($this->CI->uri->segment(1) == FALSE) ? 'default.' : $this->CI->uri->segment(1).'+';
$uri .= ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
- $dir_path = $this->CI->db->cachedir.$uri.'/';
+ $dir_path = $this->db->cachedir.$uri.'/';
$filename = md5($sql);
@@ -166,7 +168,7 @@
$segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2);
}
- $dir_path = $this->CI->db->cachedir.$segment_one.'+'.$segment_two.'/';
+ $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
delete_files($dir_path, TRUE);
}
@@ -181,11 +183,11 @@
*/
function delete_all()
{
- delete_files($this->CI->db->cachedir, TRUE);
+ delete_files($this->db->cachedir, TRUE);
}
}
-
-/* End of file DB_cache.php */
+
+/* End of file DB_cache.php */
/* Location: ./system/database/DB_cache.php */
\ No newline at end of file