瀏覽代碼

缓存策略修改

ajun 5 年之前
父節點
當前提交
7364fcf451

+ 4 - 2
app/Services/CommodityService.php

@@ -8,9 +8,11 @@ use App\CommodityBarcode;
 use App\OracleBasSKU;
 use App\Owner;
 use App\Services\common\BatchUpdateService;
+use App\Shop;
 use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\Cache;
 
 Class CommodityService
 {
@@ -356,7 +358,7 @@ Class CommodityService
         if(count($map) == 0) return $collect;
         $date = Carbon::now();
         foreach ($map as $item) {
-            $collect->push($this->cacheService->getOrExecute("owner_code_{$item['owner_code']}_sku_{$item['sku']}",function()use($item,$owner_map,$date){
+            $collect->push(Cache::remember("owner_code_{$item['owner_code']}_sku_{$item['sku']}", null, function()use($item,$owner_map,$date){
                 $owner = $owner_map[$item['owner_code']];
                 $commodity = Commodity::query()->where('owner_id',$owner['id'])->where('sku',$item['sku'])->first();
                 if($commodity)return $commodity;
@@ -371,7 +373,7 @@ Class CommodityService
                     'width' => $basSku['skuwidth'],
                     'height' => $basSku['skuhigh'],
                     'volumn' => $basSku['cube']]);
-            },config('cache.expirations.forever')));
+            }));
         }
         return $collect;
     }

+ 4 - 2
app/Services/LogisticService.php

@@ -4,9 +4,11 @@ namespace App\Services;
 
 use App\Logistic;
 use App\OracleBasCustomer;
+use App\Shop;
 use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Str;
 
 Class LogisticService
@@ -93,7 +95,7 @@ Class LogisticService
         $collect = collect();
         if(count($codes) == 0) return $collect;
         foreach ($codes as $code) {
-            $collect->push($this->cacheService->getOrExecute('getLogisticByCodes_'.$code,function()use($code){
+            $collect->push(Cache::remember("getLogisticByCodes_{$code}", null, function()use($code){
                 $logistic = Logistic::query()->where('code',$code)->first();
                 if($logistic)return $logistic;
                 $baseCustomers = OracleBasCustomer::query()
@@ -101,7 +103,7 @@ Class LogisticService
                     ->where('Customer_Type','CA')
                     ->where('CustomerID',$code)->first();
                 return Logistic::query()->create(['name'=>$baseCustomers['descr_c'],'code'=>$baseCustomers['customerid']]);
-            }),config('cache.expirations.forever'));
+            }));
         }
         return $collect;
     }

+ 3 - 2
app/Services/OwnerService.php

@@ -9,6 +9,7 @@ use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
 
 Class OwnerService
 {
@@ -221,12 +222,12 @@ Class OwnerService
         $collect = collect();
         if(count($codes) == 0)return $collect;
         foreach ($codes as $code) {
-            $collect->push($this->cacheService->getOrExecute("getOwnerByCodes_{$code}",function ()use($code){
+            $collect->push(Cache::remember("getOwnerByCodes_{$code}", null, function ()use($code){
                 $owner = Owner::query()->where('code',$code)->first();
                 if($owner) return $owner;
                 $basCustomer = OracleBasCustomer::query()->where('Customer_Type','OW')->where('CustomerID', $code)->first();
                 return Owner::query()->create(['name'=>$basCustomer['descr_c'],'code'=>$basCustomer['customerid']]);
-            },config('cache.expirations.forever')));
+            }));
         }
         return $collect;
     }

+ 4 - 2
app/Services/ShopService.php

@@ -2,10 +2,12 @@
 
 namespace App\Services;
 
+use App\OracleBasCustomer;
 use App\Owner;
 use App\Services\common\BatchUpdateService;
 use App\Shop;
 use Carbon\Carbon;
+use Illuminate\Support\Facades\Cache;
 
 class ShopService
 {
@@ -108,12 +110,12 @@ class ShopService
         $collect = collect();
         if(count($map)==0)return $collect;
         foreach ($map as $item) {
-            $collect->push($this->cacheService->getOrExecute("getShopByCodeMap_{$item['owner_code']}_{$item['issuepartyname']}",function()use($item,$owner_map){
+            $collect->push(Cache::remember("getShopByCodeMap_{$item['owner_code']}_{$item['issuepartyname']}", null, function()use($item,$owner_map){
                 $owner = $owner_map[$item['owner_code']] ;
                 $shop = Shop::query()->where('owner_id',$owner['id'])->where('name',$item['issuepartyname'])->first();
                 if($shop)return $shop;
                 return Shop::query()->create(['owner_id'=>$owner['id'],'name'=>$item['issuepartyname']]);
-            },config('cache.expirations.forever')));
+            }));
         }
         return $collect;
     }