提交 0532cc89 编写于 作者: 李光春's avatar 李光春

- 优化缓存数据库驱动

上级 5132f6af
...@@ -47,10 +47,10 @@ class Mysql ...@@ -47,10 +47,10 @@ class Mysql
/** /**
* 过期时间 * 过期时间
* @param string $cache_expire * @param int $cache_expire
* @return $this * @return $this
*/ */
public function expire(string $cache_expire) public function expire(int $cache_expire)
{ {
$this->cache_expire = $cache_expire; $this->cache_expire = $cache_expire;
return $this; return $this;
...@@ -69,7 +69,7 @@ class Mysql ...@@ -69,7 +69,7 @@ class Mysql
->insert([ ->insert([
'cache_name' => $this->cache_name, 'cache_name' => $this->cache_name,
'cache_value' => $cache_value, '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 ...@@ -89,7 +89,7 @@ class Mysql
->field('cache_expire,cache_value') ->field('cache_expire,cache_value')
->find(); ->find();
if (empty($cache['cache_expire'])) return $cache['cache_value']; 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']; return $cache['cache_value'];
} }
...@@ -102,9 +102,10 @@ class Mysql ...@@ -102,9 +102,10 @@ class Mysql
public function delete() public function delete()
{ {
if (empty($this->cache_name)) throw new CacheException("名称未配置"); if (empty($this->cache_name)) throw new CacheException("名称未配置");
return Db::table($this->table) $result = Db::table($this->table)
->where('cache_name', $this->cache_name) ->where('cache_name', $this->cache_name)
->delete(); ->delete();
return $result ? true : false;
} }
/** /**
...@@ -118,18 +119,20 @@ class Mysql ...@@ -118,18 +119,20 @@ class Mysql
{ {
if (empty($this->cache_name)) throw new CacheException("名称未配置"); if (empty($this->cache_name)) throw new CacheException("名称未配置");
if (empty($this->cache_expire)) { if (empty($this->cache_expire)) {
return Db::table($this->table) $result = Db::table($this->table)
->where('cache_name', $this->cache_name) ->where('cache_name', $this->cache_name)
->update([ ->update([
'cache_value' => $this->cache_expire, 'cache_value' => $cache_value,
]); ]);
return $result ? true : false;
} else { } else {
return Db::table($this->table) $result = Db::table($this->table)
->where('cache_name', $this->cache_name) ->where('cache_name', $this->cache_name)
->update([ ->update([
'cache_value' => $cache_value, '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;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册