| 123456789101112131415161718192021222324252627 |
- <?php
- namespace App\Services;
- use Illuminate\Support\Facades\Cache;
- use App\Traits\ServiceAppAop;
- class CacheService
- {
- use ServiceAppAop;
- function getOrExecute(String $key, $func, $expiration=null){
- if(!$expiration) $expiration=config('cache.expirations.default');
- return Cache::remember($key, $expiration, $func);
- // $results = Cache::get($key);
- // if(!$results){
- // if(!$func||gettype($func)!='object') throw new \Exception('执行函数类型错误');
- // $results = $func();
- // if(!$results)return null;
- // if(!$expiration) $expiration=config('cache.expirations.default');
- // Cache::put($key, $results, $expiration);
- // }
- // return $results;
- }
- }
|