59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Module\Datacenter;
|
|
|
|
use App\Repositories\BaseCachedRepository;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class DatacenterCachedRepository extends BaseCachedRepository implements DatacenterRepositoryInterface
|
|
{
|
|
public function __construct(
|
|
public DatacenterRepository $datacenterRepository
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
public function getModel()
|
|
{
|
|
return $this->datacenterRepository->getModel();
|
|
}
|
|
public function filter(
|
|
array $data = [],
|
|
array $relationships = [],
|
|
array $withCount = [],
|
|
array $select = ['*'],
|
|
bool $returnQuery = false
|
|
) {
|
|
if (
|
|
$returnQuery ||
|
|
!empty($data['paginate'])
|
|
) {
|
|
return $this->datacenterRepository
|
|
->filter($data, $relationships, $withCount, $select, $returnQuery);
|
|
}
|
|
|
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
|
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
|
])));
|
|
|
|
return Cache::remember(
|
|
$cacheKey,
|
|
$this->cacheTime,
|
|
fn() =>
|
|
$this->datacenterRepository
|
|
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
|
);
|
|
}
|
|
public function findBy(string $key = '', string|int|null $value = '')
|
|
{
|
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
|
'findBy' => [
|
|
'key' => $key,
|
|
'value' => $value
|
|
]
|
|
])));
|
|
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
|
return $this->datacenterRepository->findBy($key, $value);
|
|
});
|
|
}
|
|
}
|