Files
portal-api/app/Repositories/Module/HostingServer/HostingServerCachedRepository.php
T
2026-09-28 08:26:29 +07:00

67 lines
1.9 KiB
PHP

<?php
namespace App\Repositories\Module\HostingServer;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class HostingServerCachedRepository extends BaseCachedRepository implements HostingServerRepositoryInterface
{
public function __construct(
public HostingServerRepository $hostingServerRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->hostingServerRepository->getModel();
}
public function get_active()
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'get_active'
])));
return Cache::remember($cacheKey, $this->cacheTime, function () {
return $this->hostingServerRepository->get_active();
});
}
public function findByName(string $name = '')
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'findByName' => [
'name' => $name
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($name){
return $this->hostingServerRepository->findByName($name);
});
}
public function filter(
array $data = [],
array $relationships = [],
array $withCount = [],
array $select = ['*'],
bool $returnQuery = false
) {
if (
$returnQuery ||
!empty($data['paginate'])
) {
return $this->hostingServerRepository
->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->hostingServerRepository
->filter($data, $relationships, $withCount, $select, $returnQuery)
);
}
}