浏览代码

service autoCache 文件名问题

LD 5 年之前
父节点
当前提交
196fc0e00e
共有 2 个文件被更改,包括 2 次插入38 次删除
  1. 1 35
      app/Services/MaterialBoxService.php
  2. 1 3
      app/Traits/ServiceAppAop.php

+ 1 - 35
app/Services/MaterialBoxService.php

@@ -15,39 +15,5 @@ class MaterialBoxService
     use ServiceAppAop;
     protected $modelClass=MaterialBox::class;
 
-//    function get(array $kvPairs):?Collection{
-//        return Cache::remember($this->cachingKey($kvPairs), config('cache.expirations.rarelyChange'), function ()use($kvPairs) {
-//            $query = MaterialBox::query();
-//            foreach ($kvPairs as $column => $value){
-//                if (is_array($value))$query->whereIn($column,$value);
-//                else $query->where($column,$value);
-//            }
-//            return $query->get();
-//        });
-//    }
-//
-//    protected function cachingKey(array $kvPairs){
-//        ksort($kvPairs);
-//        return 'MaterialBox_'.md5(json_encode($kvPairs));
-//    }
-//
-//    protected function clearCache(array $kvPairs){
-//        Cache::forget($this->cachingKey($kvPairs));
-//    }
-//
-//    function create(array $kvPairs){
-//        $materialBox=$this->get($kvPairs);
-//        if($materialBox->isNotEmpty())
-//            return $materialBox->first();
-//        $this->clearCache($kvPairs);
-//        return MaterialBox::query()->create($kvPairs);
-//    }
-//
-//    function firstOrCreate(array $kvPairs){
-//        $materialBox=$this->get($kvPairs);
-//        if($materialBox->isNotEmpty())
-//            return $materialBox->first();
-//        $this->clearCache($kvPairs);
-//        return $this->create($kvPairs);
-//    }
+
 }

+ 1 - 3
app/Traits/ServiceAppAop.php

@@ -4,8 +4,6 @@
 namespace App\Traits;
 
 
-use App\Exceptions\FatalException;
-use App\MaterialBox;
 use Illuminate\Contracts\Foundation\Application;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Cache;
@@ -53,7 +51,7 @@ trait ServiceAppAop
     protected function cachingKey(array $kvPairs): string
     {
         ksort($kvPairs);
-        return 'MaterialBox_'.md5(json_encode($kvPairs));
+        return $this->modelClass.md5(json_encode($kvPairs));
     }
 
     protected function clearCache(array $kvPairs){