Commit 9cd67bb6 by Qiang Xue

Fixed query and schema caching renamings.

parent 9d75714b
...@@ -106,12 +106,11 @@ class DbCache extends Cache ...@@ -106,12 +106,11 @@ class DbCache extends Cache
->from($this->cacheTableName) ->from($this->cacheTableName)
->where('id = :id AND (expire = 0 OR expire > :time)', array(':id' => $key, ':time' => time())); ->where('id = :id AND (expire = 0 OR expire > :time)', array(':id' => $key, ':time' => time()));
$db = $this->getDbConnection(); $db = $this->getDbConnection();
if ($db->queryCachingDuration >= 0) { if ($db->enableQueryCache) {
// temporarily disable and re-enable query caching // temporarily disable and re-enable query caching
$duration = $db->queryCachingDuration; $db->enableQueryCache = false;
$db->queryCachingDuration = -1;
$result = $query->createCommand($db)->queryScalar(); $result = $query->createCommand($db)->queryScalar();
$db->queryCachingDuration = $duration; $db->enableQueryCache = true;
return $result; return $result;
} else { } else {
return $query->createCommand($db)->queryScalar(); return $query->createCommand($db)->queryScalar();
...@@ -135,11 +134,10 @@ class DbCache extends Cache ...@@ -135,11 +134,10 @@ class DbCache extends Cache
->andWhere("expire = 0 OR expire > " . time() . ")"); ->andWhere("expire = 0 OR expire > " . time() . ")");
$db = $this->getDbConnection(); $db = $this->getDbConnection();
if ($db->queryCachingDuration >= 0) { if ($db->enableQueryCache) {
$duration = $db->queryCachingDuration; $db->enableQueryCache = false;
$db->queryCachingDuration = -1;
$rows = $query->createCommand($db)->queryAll(); $rows = $query->createCommand($db)->queryAll();
$db->queryCachingDuration = $duration; $db->enableQueryCache = true;
} else { } else {
$rows = $query->createCommand($db)->queryAll(); $rows = $query->createCommand($db)->queryAll();
} }
......
...@@ -69,12 +69,11 @@ class DbDependency extends Dependency ...@@ -69,12 +69,11 @@ class DbDependency extends Dependency
{ {
$db = $this->getDbConnection(); $db = $this->getDbConnection();
$command = $this->query->createCommand($db); $command = $this->query->createCommand($db);
if ($db->queryCachingDuration >= 0) { if ($db->enableQueryCache) {
// temporarily disable and re-enable query caching // temporarily disable and re-enable query caching
$duration = $db->queryCachingDuration; $db->enableQueryCache = false;
$db->queryCachingDuration = -1;
$result = $command->queryRow(); $result = $command->queryRow();
$db->queryCachingDuration = $duration; $db->enableQueryCache = true;
} else { } else {
$result = $command->queryRow(); $result = $command->queryRow();
} }
......
...@@ -405,7 +405,7 @@ class Command extends \yii\base\Component ...@@ -405,7 +405,7 @@ class Command extends \yii\base\Component
} }
if (isset($cache)) { 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__); \Yii::trace('Saved query result in cache', __CLASS__);
} }
......
...@@ -95,18 +95,13 @@ abstract class Driver extends \yii\base\Object ...@@ -95,18 +95,13 @@ abstract class Driver extends \yii\base\Object
$realName = $db->expandTablePrefix($name); $realName = $db->expandTablePrefix($name);
// temporarily disable query caching /** @var $cache \yii\caching\Cache */
if ($db->queryCachingDuration >= 0) { if ($db->enableSchemaCache && ($cache = \Yii::$application->getComponent($db->schemaCacheID)) !== null && !in_array($name, $db->schemaCacheExclude, true)) {
$qcDuration = $db->queryCachingDuration;
$db->queryCachingDuration = -1;
}
if (!in_array($name, $db->schemaCachingExclude, true) && $db->schemaCachingDuration >= 0 && ($cache = \Yii::$application->getComponent($db->schemaCacheID)) !== null) {
$key = $this->getCacheKey($name); $key = $this->getCacheKey($name);
if ($refresh || ($table = $cache->get($key)) === false) { if ($refresh || ($table = $cache->get($key)) === false) {
$table = $this->loadTableSchema($realName); $table = $this->loadTableSchema($realName);
if ($table !== null) { if ($table !== null) {
$cache->set($key, $table, $db->schemaCachingDuration); $cache->set($key, $table, $db->schemaCacheDuration);
} }
} }
$this->_tables[$name] = $table; $this->_tables[$name] = $table;
...@@ -114,10 +109,6 @@ abstract class Driver extends \yii\base\Object ...@@ -114,10 +109,6 @@ abstract class Driver extends \yii\base\Object
$this->_tables[$name] = $table = $this->loadTableSchema($realName); $this->_tables[$name] = $table = $this->loadTableSchema($realName);
} }
if (isset($qcDuration)) { // re-enable query caching
$db->queryCachingDuration = $qcDuration;
}
return $table; return $table;
} }
...@@ -185,7 +176,8 @@ abstract class Driver extends \yii\base\Object ...@@ -185,7 +176,8 @@ abstract class Driver extends \yii\base\Object
public function refresh($tableName = null) public function refresh($tableName = null)
{ {
$db = $this->connection; $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) { if ($tableName === null) {
foreach ($this->_tables as $name => $table) { foreach ($this->_tables as $name => $table) {
$cache->delete($this->getCacheKey($name)); $cache->delete($this->getCacheKey($name));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment