summaryrefslogtreecommitdiffstats
path: root/system/database/DB_driver.php
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-10-02 08:46:16 +0200
committeradmin <devnull@localhost>2006-10-02 08:46:16 +0200
commite8f6eb62a0600daf5b192746e1eed3e81516bc92 (patch)
tree0f2c39dda00a4adf6d01a596ce977962b2c2a12a /system/database/DB_driver.php
parent3cad41e56fe4edc057cf6a84952a343686376429 (diff)
Diffstat (limited to 'system/database/DB_driver.php')
-rw-r--r--system/database/DB_driver.php107
1 files changed, 99 insertions, 8 deletions
diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php
index 81af466ef..73c723d96 100644
--- a/system/database/DB_driver.php
+++ b/system/database/DB_driver.php
@@ -41,11 +41,13 @@ class CI_DB_driver {
var $conn_id = FALSE;
var $result_id = FALSE;
var $db_debug = FALSE;
+ var $query_caching = FALSE;
+ var $cache_dir = '';
var $benchmark = 0;
var $query_count = 0;
var $bind_marker = '?';
var $queries = array();
- var $cache = array();
+ var $data_cache = array();
var $trans_enabled = TRUE;
var $_trans_depth = 0;
var $_trans_failure = FALSE; // Used with transactions to determine if a rollback should occur
@@ -55,6 +57,7 @@ class CI_DB_driver {
var $curs_id;
var $limit_used;
+
/**
* Constructor. Accepts one parameter containing the database
@@ -214,6 +217,21 @@ class CI_DB_driver {
return FALSE;
}
+ // Is query caching enabled? If the query is a "read type" we'll
+ // grab the previously cached query if it exists and return it.
+ if ($this->query_caching == TRUE)
+ {
+ if (stristr($sql, 'SELECT'))
+ {
+ $CACHE =& _load_cache_class();
+
+ if (FALSE !== ($CACHE->cache_exists($sql)))
+ {
+ return $CACHE->get_cache($sql);
+ }
+ }
+ }
+
// Compile binds if needed
if ($binds !== FALSE)
{
@@ -257,7 +275,7 @@ class CI_DB_driver {
// Was the query a "write" type?
// If so we'll simply return true
if ($this->is_write_type($sql) === TRUE)
- {
+ {
return TRUE;
}
@@ -564,9 +582,9 @@ class CI_DB_driver {
function list_tables()
{
// Is there a cached result?
- if (isset($this->cache['table_names']))
+ if (isset($this->data_cache['table_names']))
{
- return $this->cache['table_names'];
+ return $this->data_cache['table_names'];
}
if (FALSE === ($sql = $this->_list_tables()))
@@ -596,7 +614,7 @@ class CI_DB_driver {
}
}
- return $this->cache['table_names'] =& $retval;
+ return $this->data_cache['table_names'] =& $retval;
}
// --------------------------------------------------------------------
@@ -623,9 +641,9 @@ class CI_DB_driver {
function list_fields($table = '')
{
// Is there a cached result?
- if (isset($this->cache['field_names'][$table]))
+ if (isset($this->data_cache['field_names'][$table]))
{
- return $this->cache['field_names'][$table];
+ return $this->data_cache['field_names'][$table];
}
if ($table == '')
@@ -661,7 +679,7 @@ class CI_DB_driver {
}
}
- return $this->cache['field_names'][$table] =& $retval;
+ return $this->data_cache['field_names'][$table] =& $retval;
}
// --------------------------------------------------------------------
@@ -820,6 +838,79 @@ class CI_DB_driver {
return call_user_func_array($function, $args);
}
}
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Set Cache Path
+ *
+ * @access public
+ * @param string the path to the cache directory
+ * @return void
+ */
+ function set_cache_path($path = '')
+ {
+ if ( ! is_dir($path) OR ! is_writable($path))
+ {
+ if ($this->db_debug)
+ {
+ return $this->display_error('db_invalid_cache_path');
+ }
+
+ $this->enable_caching(FALSE);
+ return FALSE;
+ }
+
+ $this->cache_dir = $path;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Enable Query Caching
+ *
+ * @access public
+ * @return void
+ */
+ function cache_on()
+ {
+ $this->query_caching = TRUE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Disable Query Caching
+ *
+ * @access public
+ * @return void
+ */
+ function cache_off()
+ {
+ $this->query_caching = FALSE;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Load Caching Class
+ *
+ * @access private
+ * @return object
+ */
+ function _load_cache_class()
+ {
+ static $CACHE = NULL;
+
+ if (is_object($CACHE))
+ {
+ return $CACHE;
+ }
+
+ require_once BASEPATH.'database/DB_cache'.EXT;
+ $CACHE = new DB_cache();
+ return $CACHE;
+ }
// --------------------------------------------------------------------