diff options
author | Derek Jones <derek.jones@ellislab.com> | 2008-05-12 17:17:41 +0200 |
---|---|---|
committer | Derek Jones <derek.jones@ellislab.com> | 2008-05-12 17:17:41 +0200 |
commit | d36ade01b57ac39c328d9e0278b28b04fbef895e (patch) | |
tree | 2d88a4f975a89e0588b6c8f34428cdd497b3d2c5 /system | |
parent | 500fa6c3a934ac9d9f0a5c1ded5c00ad1709187f (diff) |
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/
Diffstat (limited to 'system')
-rw-r--r-- | system/database/DB_cache.php | 30 | ||||
-rw-r--r-- | system/database/DB_driver.php | 2 |
2 files changed, 17 insertions, 15 deletions
diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index 21113aff3..448727fd0 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 @@ class CI_DB_Cache { * 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 @@ class CI_DB_Cache { {
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 @@ class CI_DB_Cache { 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 @@ class CI_DB_Cache { {
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 @@ class CI_DB_Cache { $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 @@ class CI_DB_Cache { {
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 @@ class CI_DB_Cache { $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 @@ class CI_DB_Cache { */
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 35bdc29b6..b055d6dc3 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1083,7 +1083,7 @@ class CI_DB_driver { 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;
}
|