CacheService.php 638 B

1234567891011121314151617181920212223
  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. return Cache::remember($key, $expiration, $func);
  8. // $results = Cache::get($key);
  9. // if(!$results){
  10. // if(!$func||gettype($func)!='object') throw new \Exception('执行函数类型错误');
  11. // $results = $func();
  12. // if(!$results)return null;
  13. // if(!$expiration) $expiration=config('cache.expirations.default');
  14. // Cache::put($key, $results, $expiration);
  15. // }
  16. // return $results;
  17. }
  18. }