Files
portal-api/app/Repositories/OsGroup/OsGroupCachedRepository.php
T
2026-02-02 09:07:33 +07:00

58 lines
1.8 KiB
PHP

<?php
namespace App\Repositories\OsGroup;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class OsGroupCachedRepository extends BaseCachedRepository implements OsGroupRepositoryInterface
{
public function __construct(public OsGroupRepository $osGroupRepository)
{
parent::__construct();
}
public function getModel()
{
return $this->osGroupRepository->getModel();
}
public function filter(
array $data = [],
array $relationships = [],
array $withCount = [],
array $select = ['*'],
bool $returnQuery = false
) {
if (
$returnQuery ||
!empty($data['paginate'])
) {
return $this->osGroupRepository
->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->osGroupRepository
->filter($data, $relationships, $withCount, $select, $returnQuery)
);
}
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->osGroupRepository->findWithRelationships($id, $relationships, $withCount, $withSum);
});
}
}