From 0532cc89be980964fa379ba4d66b568d3f028990 Mon Sep 17 00:00:00 2001 From: Chaim Date: Mon, 18 May 2020 20:47:37 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cache/Mysql.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/cache/Mysql.php b/src/cache/Mysql.php index 4fd68a7..22faf64 100644 --- a/src/cache/Mysql.php +++ b/src/cache/Mysql.php @@ -47,10 +47,10 @@ class Mysql /** * 过期时间 - * @param string $cache_expire + * @param int $cache_expire * @return $this */ - public function expire(string $cache_expire) + public function expire(int $cache_expire) { $this->cache_expire = $cache_expire; return $this; @@ -69,7 +69,7 @@ class Mysql ->insert([ 'cache_name' => $this->cache_name, 'cache_value' => $cache_value, - 'cache_expire' => Times::dateRear($this->cache_expire) + 'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire) ]); } @@ -89,7 +89,7 @@ class Mysql ->field('cache_expire,cache_value') ->find(); if (empty($cache['cache_expire'])) return $cache['cache_value']; - if ($cache['cache_expire'] < time()) return ""; + if ($cache['cache_expire'] < time()) return false; return $cache['cache_value']; } @@ -102,9 +102,10 @@ class Mysql public function delete() { if (empty($this->cache_name)) throw new CacheException("名称未配置"); - return Db::table($this->table) + $result = Db::table($this->table) ->where('cache_name', $this->cache_name) ->delete(); + return $result ? true : false; } /** @@ -118,18 +119,20 @@ class Mysql { if (empty($this->cache_name)) throw new CacheException("名称未配置"); if (empty($this->cache_expire)) { - return Db::table($this->table) + $result = Db::table($this->table) ->where('cache_name', $this->cache_name) ->update([ - 'cache_value' => $this->cache_expire, + 'cache_value' => $cache_value, ]); + return $result ? true : false; } else { - return Db::table($this->table) + $result = Db::table($this->table) ->where('cache_name', $this->cache_name) ->update([ 'cache_value' => $cache_value, - 'cache_expire' => $this->cache_expire + 'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire) ]); + return $result ? true : false; } }