- 修复缓存数据库驱动获取不到数据问题

v6 v6.0.19
Chaim 4 years ago
parent f66f51a9e6
commit 237efe1ce8

@ -18,9 +18,7 @@ namespace DtApp\ThinkLibrary\cache;
use DtApp\ThinkLibrary\exception\CacheException; use DtApp\ThinkLibrary\exception\CacheException;
use DtApp\ThinkLibrary\facade\Times; use DtApp\ThinkLibrary\facade\Times;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db; use think\facade\Db;
/** /**
@ -77,21 +75,15 @@ class Mysql
* 获取 * 获取
* @return string * @return string
* @throws CacheException * @throws CacheException
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
*/ */
public function get() public function get()
{ {
if (empty($this->cache_name)) throw new CacheException("名称未配置"); if (empty($this->cache_name)) throw new CacheException("名称未配置");
$cache = Db::table($this->table) return Db::table($this->table)
->where('cache_name', $this->cache_name) ->where('cache_name', $this->cache_name)
->order('id desc') ->order('id desc')
->field('cache_expire,cache_value') ->whereTime('cache_expire', '>', time())
->find(); ->value('cache_value', '');
if (empty($cache['cache_expire'])) return $cache['cache_value'];
if ($cache['cache_expire'] < time()) return false;
return $cache['cache_value'];
} }
/** /**
@ -119,22 +111,13 @@ class Mysql
public function update($cache_value) public function update($cache_value)
{ {
if (empty($this->cache_name)) throw new CacheException("名称未配置"); if (empty($this->cache_name)) throw new CacheException("名称未配置");
if (empty($this->cache_expire)) { $result = 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' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire)
]); ]);
return $result ? true : false; return $result ? true : false;
} else {
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value,
'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire)
]);
return $result ? true : false;
}
} }
/** /**

Loading…
Cancel
Save