- 助手函数增加缓存

v6
Chaim 4 years ago
parent 8fb4a4b3f6
commit b014b90d93

@ -18,7 +18,9 @@ namespace DtApp\ThinkLibrary\cache;
use DtApp\ThinkLibrary\exception\CacheException;
use DtApp\ThinkLibrary\facade\Times;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Db;
/**
@ -76,15 +78,19 @@ class Mysql
* 获取
* @return string
* @throws CacheException
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
*/
public function get()
{
if (empty($this->cache_name)) throw new CacheException("名称未配置");
return Db::table($this->table)
$cache = Db::table($this->table)
->where('cache_name', $this->cache_name)
->order('id desc')
->whereTime('cache_expire', '>', time())
->value('cache_value', '');
->find();
return $cache['cache_value'];
}
/**

@ -125,12 +125,9 @@ if (!function_exists('dtacache')) {
{
$myc = new Mysql();
if (empty($value)) {
$data = $myc->name($name)
return $myc->name($name)
->get();
if (is_null(json_decode($data))) return json_decode($data, true);
else return $data;
} else {
if (is_array($value)) $value = json_encode($value);
$myc->name($name)
->expire($expire)
->set($value);

Loading…
Cancel
Save