<?php


namespace App\Services;


use Illuminate\Support\Facades\Cache;
use App\Traits\ServiceAppAop;


class CacheService
{
    use ServiceAppAop;
    protected $modelClass=Cache::class;
    function getOrExecute(String $key, $func, $expiration=-1){
        if($expiration === -1) $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;
    }
}
