| ... | ... | @@ -28,6 +28,12 @@ trait DbQuery { | 
|  |  | */ | 
|  |  | protected int $cache = 0; | 
|  |  |  | 
|  |  | /** | 
|  |  | * 没有数据时 也缓存 | 
|  |  | * @var bool | 
|  |  | */ | 
|  |  | protected bool $cacheNoData = true; | 
|  |  |  | 
|  |  |  | 
|  |  | public function getClient() | 
|  |  | { | 
| ... | ... | @@ -51,8 +57,9 @@ trait DbQuery { | 
|  |  | * @author:dc | 
|  |  | * @time 2024/8/14 14:04 | 
|  |  | */ | 
|  |  | public function cache(int $ttl){ | 
|  |  | public function cache(int $ttl,bool $noData = true){ | 
|  |  | $this->cache = $ttl; | 
|  |  | $this->cacheNoData = $noData; | 
|  |  | return $this; | 
|  |  | } | 
|  |  |  | 
| ... | ... | @@ -278,7 +285,13 @@ trait DbQuery { | 
|  |  | $key = 'data:'.md5(is_string($sql) ? $sql : json_encode($sql)); | 
|  |  | if(redis()->has($key)){ | 
|  |  | $this->cache = 0; | 
|  |  | return redis()->get($key,$default); | 
|  |  | $data =  redis()->get($key,$default); | 
|  |  | if(!$this->cacheNoData){ | 
|  |  | if($data || $data === 0){ | 
|  |  | return $data; | 
|  |  | } | 
|  |  | } | 
|  |  |  | 
|  |  | } | 
|  |  | } | 
|  |  | $query = $this->query($sql); | 
... | ... |  |