Skip to content

Commit

Permalink
修正查询缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
Hhh0121 committed Mar 28, 2024
1 parent e35f497 commit 64f9f17
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/db/PDOConnection.php
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 64f9f17

Please sign in to comment.