CacheService.php 712 B

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