Files
portal-api/app/Repositories/Domain/DomainCachedRepository.php
T
2025-07-24 16:18:27 +07:00

49 lines
1.7 KiB
PHP

<?php
namespace App\Repositories\Domain;
use App\Models\Domain;
use App\Repositories\BaseCachedRepository;
use App\Repositories\BaseRepository;
use Illuminate\Support\Facades\Cache;
class DomainCachedRepository extends BaseCachedRepository implements DomainRepositoryInterface
{
public function __construct(
public DomainRepository $domainRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->domainRepository->getModel();
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$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->domainRepository->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
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships,$withCount,$withSum) {
return $this->domainRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
});
}
}