58 lines
2.1 KiB
PHP
58 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Order;
|
|
|
|
use App\Repositories\BaseCachedRepository;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class OrderCachedRepository extends BaseCachedRepository implements OrderRepositoryInterface
|
|
{
|
|
public function __construct(
|
|
public OrderRepository $orderRepository
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
public function getModel()
|
|
{
|
|
return $this->orderRepository->getModel();
|
|
}
|
|
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'], bool $returnQuery = false)
|
|
{
|
|
if ($returnQuery) {
|
|
return $this->orderRepository->filter($data, $relationships, $withCount, $select, true);
|
|
}
|
|
|
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
|
'filterItem' => [
|
|
'data' => $data,
|
|
'relationships' => $relationships,
|
|
'select' => $select,
|
|
'withCount' => $withCount
|
|
]
|
|
])));
|
|
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
|
|
return $this->orderRepository->filter($data, $relationships, $withCount, $select);
|
|
});
|
|
}
|
|
public function findWithRelationships(int $id = 0, array $relationships = [],array $withCount = [], array $withSum = [])
|
|
{
|
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
|
'findWithRelationships' => [
|
|
'id' => $id,
|
|
'relationships' => $relationships,
|
|
'withCount' => $withCount,
|
|
'withSum' => $withSum
|
|
]
|
|
])));
|
|
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
|
|
return $this->orderRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
|
|
});
|
|
}
|
|
public function updateBy(string $key = '', string|int $value = '', array $data = [])
|
|
{
|
|
$this->orderRepository->updateBy($key, $value,$data);
|
|
$this->clearCache();
|
|
return $this;
|
|
}
|
|
}
|