Files
portal-api/app/Repositories/vCenter/vCenterCachedRepository.php
T

47 lines
1.4 KiB
PHP

<?php
namespace App\Repositories\vCenter;
use App\Repositories\BaseCachedRepository;
use App\Support\Cache\CacheKey;
class vCenterCachedRepository extends BaseCachedRepository implements vCenterRepositoryInterface
{
public function __construct(
public vCenterRepository $vCenterRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->vCenterRepository->getModel();
}
public function filter(
array $data = [],
array $relationships = [],
array $withCount = [],
array $select = ['*'],
bool $returnQuery = false
) {
if (
$returnQuery ||
!empty($data['paginate'])
) {
return $this->vCenterRepository
->filter($data, $relationships, $withCount, $select, $returnQuery);
}
return $this->rememberFilter(
compact('data', 'relationships', 'withCount', 'select'),
fn() => $this->vCenterRepository->filter($data, $relationships, $withCount, $select, $returnQuery)
);
}
public function findByName(string $name = '')
{
$cacheKey = CacheKey::build($this->getModuleName(), 'find-by-name', ['name' => $name]);
return $this->cache->remember($cacheKey, function () use ($name) {
return $this->vCenterRepository->findByName($name);
});
}
}