From 64f9f17e253236350481d2ce40000bac22bfddaa Mon Sep 17 00:00:00 2001 From: Hhh0121 <2607250025@qq.com> Date: Thu, 28 Mar 2024 16:06:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=9F=A5=E8=AF=A2=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db/PDOConnection.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/db/PDOConnection.php b/src/db/PDOConnection.php index cfdcce72..76e44b13 100644 --- a/src/db/PDOConnection.php +++ b/src/db/PDOConnection.php @@ -1252,14 +1252,16 @@ public function value(BaseQuery $query, string $field, $default = null, bool $on $pdo = $this->getPDOStatement($sql, $query->getBind(), $options['master']); $result = $pdo->fetchColumn(); + $result = false !== $result ? $result : $default; + $requireCache = $query->getOptions('cache_always') || !empty($result); - if (isset($cacheItem)) { + if (isset($cacheItem) && $requireCache) { // 缓存数据 $cacheItem->set($result); $this->cacheData($cacheItem); } - return false !== $result ? $result : $default; + return $result; } /** @@ -1374,7 +1376,9 @@ public function column(BaseQuery $query, string|array $column, string $key = '') $result = $resultSet; } - if (isset($cacheItem)) { + $requireCache = $query->getOptions('cache_always') || !empty($result); + + if (isset($cacheItem) && $requireCache) { // 缓存数据 $cacheItem->set($result); $this->cacheData($cacheItem);