From 5a63ae324ea3f501b74bbea00e25d9c9143f5ee8 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 25 Feb 2015 23:06:42 -0500 Subject: [PATCH] Fixes #7211: Query caching should properly deal with the case when query result is false --- framework/CHANGELOG.md | 1 + framework/db/Command.php | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index d6ee3222d3..9c6ac66d06 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -11,6 +11,7 @@ Yii Framework 2 Change Log - Bug #7037: `yii\console\controllers\AssetController` now correctly handles relative image URLs if source and target CSS are under same directory (klimov-paul) - Bug #7055: composite IN condition was not generated correctly for certain DBMS (nineinchnick) - Bug #7074: `yii\data\ArrayDataProvider` did not correctly handle the case `Pagination::pageSize = 0` (kirsenn, qiangxue) +- Bug #7211: Query caching should properly deal with the case when query result is false (qiangxue) - Bug #7218: `yii\captcha\CaptchaAction` should send response in JSON format (InteLigent, qiangxue) - Bug #7226: `yii\web\Request::getEtag()` should strip off `-gzip` which may be added by Apache (mcd-php) - Bug #7227: Query builder should respect column alias setting when `yii\db\Expression` is being selected (mdmunir, qiangxue) diff --git a/framework/db/Command.php b/framework/db/Command.php index 4398417d9a..d88d13f3c8 100644 --- a/framework/db/Command.php +++ b/framework/db/Command.php @@ -805,9 +805,10 @@ class Command extends Component $this->db->username, $rawSql, ]; - if (($result = $cache->get($cacheKey)) !== false) { + $result = $cache->get($cacheKey); + if (is_array($result) && isset($result[0])) { Yii::trace('Query result served from cache', 'yii\db\Command::query'); - return $result; + return $result[0]; } } } @@ -837,7 +838,7 @@ class Command extends Component } if (isset($cache, $cacheKey, $info)) { - $cache->set($cacheKey, $result, $info[1], $info[2]); + $cache->set($cacheKey, [$result], $info[1], $info[2]); Yii::trace('Saved query result in cache', 'yii\db\Command::query'); }