summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-01-19 05:12:28 +0000
committerBharat Mediratta <bharat@menalto.com>2009-01-19 05:12:28 +0000
commit5f1165698b6f1f94f43571283d9644394ec03315 (patch)
tree3adc185bf91a521825a8f95bfa9a6a74fbdbd68d
parent46d010e89d280d391935648f1f713fc784042050 (diff)
Change ORM and the MySql driver to clear static caches using
clear_cache(). This supercedes the TEST_MODE checks. Upstream ticket: http://dev.kohanaphp.com/ticket/1062
-rw-r--r--kohana/libraries/ORM.php4
-rw-r--r--kohana/libraries/drivers/Database/Mysql.php34
2 files changed, 26 insertions, 12 deletions
diff --git a/kohana/libraries/ORM.php b/kohana/libraries/ORM.php
index 72aab746..0783ebcd 100644
--- a/kohana/libraries/ORM.php
+++ b/kohana/libraries/ORM.php
@@ -890,7 +890,7 @@ class ORM_Core {
{
if ($force === TRUE OR empty($this->table_columns))
{
- if (!TEST_MODE && isset(self::$column_cache[$this->object_name]))
+ if (isset(self::$column_cache[$this->object_name]))
{
// Use cached column information
$this->table_columns = self::$column_cache[$this->object_name];
@@ -1105,6 +1105,8 @@ class ORM_Core {
// Proxy to database
$this->db->clear_cache($sql);
+ self::$column_cache = array();
+
return $this;
}
diff --git a/kohana/libraries/drivers/Database/Mysql.php b/kohana/libraries/drivers/Database/Mysql.php
index 461bda90..c24dfec3 100644
--- a/kohana/libraries/drivers/Database/Mysql.php
+++ b/kohana/libraries/drivers/Database/Mysql.php
@@ -22,6 +22,12 @@ class Database_Mysql_Driver extends Database_Driver {
protected $db_config;
/**
+ * Performance caches.
+ */
+ private $tables_cache;
+ private $fields_cache;
+
+ /**
* Sets the config for the class.
*
* @param array database configuration
@@ -29,6 +35,8 @@ class Database_Mysql_Driver extends Database_Driver {
public function __construct($config)
{
$this->db_config = $config;
+ $this->tables_cache = array();
+ $this->fields_cache = array();
Kohana::log('debug', 'MySQL Database Driver Initialized');
}
@@ -262,11 +270,7 @@ class Database_Mysql_Driver extends Database_Driver {
public function list_tables(Database $db)
{
- if (!TEST_MODE) {
- static $tables;
- } else {
- $tables = array();
- }
+ $tables =& $this->tables_cache;
if (empty($tables) AND $query = $db->query('SHOW TABLES FROM '.$this->escape_table($this->db_config['connection']['database'])))
{
@@ -286,11 +290,7 @@ class Database_Mysql_Driver extends Database_Driver {
public function list_fields($table)
{
- if (!TEST_MODE) {
- static $tables;
- } else {
- $tables = array();
- }
+ $tables =& $this->fields_cache;
if (empty($tables[$table]))
{
@@ -337,6 +337,18 @@ class Database_Mysql_Driver extends Database_Driver {
return $columns;
}
+ /**
+ * Clears the internal query cache.
+ *
+ * @param string SQL query
+ */
+ public function clear_cache($sql = NULL)
+ {
+ parent::clear_cache($sql);
+ $this->tables_cache = array();
+ $this->fields_cache = array();
+ }
+
} // End Database_Mysql_Driver Class
/**
@@ -497,4 +509,4 @@ class Mysql_Result extends Database_Result {
}
}
-} // End Mysql_Result Class \ No newline at end of file
+} // End Mysql_Result Class