From 455a18e85a6867e1213fd3f53d98cde2a8fee51d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 18 Apr 2016 12:11:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Query=E7=B1=BB=E7=9A=84cache?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 02bbf543..6bca6b0a 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1044,12 +1044,14 @@ class Query $this->parsePkWhere($data, $options); } + $resultSet = false; if (isset($options['cache'])) { // 判断查询缓存 $cache = $options['cache']; $key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options)); $resultSet = Cache::get($key); - } else { + } + if (!$resultSet) { // 生成查询SQL $sql = $this->builder()->select($options); // 执行查询操作 @@ -1116,13 +1118,14 @@ class Query } $options['limit'] = 1; - + $result = false; if (isset($options['cache'])) { // 判断查询缓存 $cache = $options['cache']; $key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options)); $result = Cache::get($key); - } else { + } + if (!$result) { // 生成查询SQL $sql = $this->builder()->select($options); // 执行查询