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
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 35bdc29..b055d6d 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -1083,7 +1083,7 @@
 			return $this->cache_off();

 		}

 		

-		$this->CACHE = new CI_DB_Cache;

+		$this->CACHE = new CI_DB_Cache($this); // pass db object to support multiple db connections and returned db objects

 		return TRUE;

 	}

 

diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 43905db..8c94d46 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -138,6 +138,7 @@
 	<li>Fixed a bug in DB_result::row() that prevented it from returning individual fields with MySQL NULL values.</li>

 	<li>Fixed a bug in the table library that could cause identically constructed rows to be dropped (#3459).</li>

 	<li>Fixed a bug (#4206) in the Directory Helper where the directory resource was not being closed, and minor improvements.</li>

+	<li>Fixed a bug (#4223) where DB caching would not work for returned DB objects or multiple DB connections.</li>

 	<li>Fixed a bug where SMTP emails were not having dot transformation performed on lines that begin with a dot.</li>

 	<li>Fixed a bug in display_error() in the DB driver that was instantiating new Language and Exception objects, and not using the error heading.</li>

 	<li>Fixed a bug (#4506) with overlay_watermark() in the Image library preventing support for PNG-24s with alpha transparency</li>