|
|
@@ -15,7 +15,6 @@ class MaterialBoxService
|
|
|
use ServiceAppAop;
|
|
|
|
|
|
function get(array $kvPairs):?Collection{
|
|
|
- ksort($kvPairs);
|
|
|
return Cache::remember($this->cachingKey($kvPairs), config('cache.expirations.rarelyChange'), function ()use($kvPairs) {
|
|
|
$query = MaterialBox::query();
|
|
|
foreach ($kvPairs as $column => $value){
|
|
|
@@ -27,16 +26,19 @@ class MaterialBoxService
|
|
|
}
|
|
|
|
|
|
protected function cachingKey(array $kvPairs){
|
|
|
+ ksort($kvPairs);
|
|
|
return 'MaterialBox_'.md5(json_encode($kvPairs));
|
|
|
}
|
|
|
- protected function cacheClear(array $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);
|
|
|
}
|
|
|
|
|
|
@@ -44,6 +46,7 @@ class MaterialBoxService
|
|
|
$materialBox=$this->get($kvPairs);
|
|
|
if($materialBox->isNotEmpty())
|
|
|
return $materialBox->first();
|
|
|
- return MaterialBox::query()->create($kvPairs);
|
|
|
+ $this->clearCache($kvPairs);
|
|
|
+ return $this->create($kvPairs);
|
|
|
}
|
|
|
}
|