From 9cd67bb6b4821f3b0fe15fb0797f29e2e859d601 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 5 Jan 2013 17:19:08 -0500 Subject: [PATCH] Fixed query and schema caching renamings. --- framework/caching/DbCache.php | 14 ++++++-------- framework/caching/DbDependency.php | 7 +++---- framework/db/Command.php | 2 +- framework/db/Driver.php | 18 +++++------------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/framework/caching/DbCache.php b/framework/caching/DbCache.php index 0eea7d5..6522df4 100644 --- a/framework/caching/DbCache.php +++ b/framework/caching/DbCache.php @@ -106,12 +106,11 @@ class DbCache extends Cache ->from($this->cacheTableName) ->where('id = :id AND (expire = 0 OR expire > :time)', array(':id' => $key, ':time' => time())); $db = $this->getDbConnection(); - if ($db->queryCachingDuration >= 0) { + if ($db->enableQueryCache) { // temporarily disable and re-enable query caching - $duration = $db->queryCachingDuration; - $db->queryCachingDuration = -1; + $db->enableQueryCache = false; $result = $query->createCommand($db)->queryScalar(); - $db->queryCachingDuration = $duration; + $db->enableQueryCache = true; return $result; } else { return $query->createCommand($db)->queryScalar(); @@ -135,11 +134,10 @@ class DbCache extends Cache ->andWhere("expire = 0 OR expire > " . time() . ")"); $db = $this->getDbConnection(); - if ($db->queryCachingDuration >= 0) { - $duration = $db->queryCachingDuration; - $db->queryCachingDuration = -1; + if ($db->enableQueryCache) { + $db->enableQueryCache = false; $rows = $query->createCommand($db)->queryAll(); - $db->queryCachingDuration = $duration; + $db->enableQueryCache = true; } else { $rows = $query->createCommand($db)->queryAll(); } diff --git a/framework/caching/DbDependency.php b/framework/caching/DbDependency.php index 1b252ea..68a1779 100644 --- a/framework/caching/DbDependency.php +++ b/framework/caching/DbDependency.php @@ -69,12 +69,11 @@ class DbDependency extends Dependency { $db = $this->getDbConnection(); $command = $this->query->createCommand($db); - if ($db->queryCachingDuration >= 0) { + if ($db->enableQueryCache) { // temporarily disable and re-enable query caching - $duration = $db->queryCachingDuration; - $db->queryCachingDuration = -1; + $db->enableQueryCache = false; $result = $command->queryRow(); - $db->queryCachingDuration = $duration; + $db->enableQueryCache = true; } else { $result = $command->queryRow(); } diff --git a/framework/db/Command.php b/framework/db/Command.php index fc8626e..c5b15ee 100644 --- a/framework/db/Command.php +++ b/framework/db/Command.php @@ -405,7 +405,7 @@ class Command extends \yii\base\Component } if (isset($cache)) { - $cache->set($cacheKey, $result, $db->queryCachingDuration, $db->queryCachingDependency); + $cache->set($cacheKey, $result, $db->queryCacheDuration, $db->queryCacheDependency); \Yii::trace('Saved query result in cache', __CLASS__); } diff --git a/framework/db/Driver.php b/framework/db/Driver.php index a04e867..4ad8d69 100644 --- a/framework/db/Driver.php +++ b/framework/db/Driver.php @@ -95,18 +95,13 @@ abstract class Driver extends \yii\base\Object $realName = $db->expandTablePrefix($name); - // temporarily disable query caching - if ($db->queryCachingDuration >= 0) { - $qcDuration = $db->queryCachingDuration; - $db->queryCachingDuration = -1; - } - - if (!in_array($name, $db->schemaCachingExclude, true) && $db->schemaCachingDuration >= 0 && ($cache = \Yii::$application->getComponent($db->schemaCacheID)) !== null) { + /** @var $cache \yii\caching\Cache */ + if ($db->enableSchemaCache && ($cache = \Yii::$application->getComponent($db->schemaCacheID)) !== null && !in_array($name, $db->schemaCacheExclude, true)) { $key = $this->getCacheKey($name); if ($refresh || ($table = $cache->get($key)) === false) { $table = $this->loadTableSchema($realName); if ($table !== null) { - $cache->set($key, $table, $db->schemaCachingDuration); + $cache->set($key, $table, $db->schemaCacheDuration); } } $this->_tables[$name] = $table; @@ -114,10 +109,6 @@ abstract class Driver extends \yii\base\Object $this->_tables[$name] = $table = $this->loadTableSchema($realName); } - if (isset($qcDuration)) { // re-enable query caching - $db->queryCachingDuration = $qcDuration; - } - return $table; } @@ -185,7 +176,8 @@ abstract class Driver extends \yii\base\Object public function refresh($tableName = null) { $db = $this->connection; - if ($db->schemaCachingDuration >= 0 && ($cache = \Yii::$application->getComponent($db->schemaCacheID)) !== null) { + /** @var $cache \yii\caching\Cache */ + if ($db->enableSchemaCache && ($cache = \Yii::$application->getComponent($db->schemaCacheID)) !== null) { if ($tableName === null) { foreach ($this->_tables as $name => $table) { $cache->delete($this->getCacheKey($name));