CacheService.php 766 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\Cache;
  4. use App\Traits\ServiceAppAop;
  5. class CacheService
  6. {
  7. use ServiceAppAop;
  8. function getOrExecute(String $key, $func, $expiration=null){
  9. if(!$expiration) $expiration=config('cache.expirations.default');
  10. return Cache::remember($key, $expiration, $func);
  11. // $results = Cache::get($key);
  12. // if(!$results){
  13. // if(!$func||gettype($func)!='object') throw new \Exception('执行函数类型错误');
  14. // $results = $func();
  15. // if(!$results)return null;
  16. // if(!$expiration) $expiration=config('cache.expirations.default');
  17. // Cache::put($key, $results, $expiration);
  18. // }
  19. // return $results;
  20. }
  21. }