58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Module\DnsServer;
|
|
|
|
use App\Repositories\BaseCachedRepository;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class DnsServerCachedRepository extends BaseCachedRepository implements DnsServerRepositoryInterface
|
|
{
|
|
public function __construct(
|
|
public DnsServerRepository $dnsServerRepository
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
public function getModel()
|
|
{
|
|
return $this->dnsServerRepository->getModel();
|
|
}
|
|
public function filter(
|
|
array $data = [],
|
|
array $relationships = [],
|
|
array $withCount = [],
|
|
array $select = ['*'],
|
|
bool $returnQuery = false
|
|
) {
|
|
if (
|
|
$returnQuery ||
|
|
!empty($data['paginate'])
|
|
) {
|
|
return $this->dnsServerRepository
|
|
->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->dnsServerRepository
|
|
->filter($data, $relationships, $withCount, $select, $returnQuery)
|
|
);
|
|
}
|
|
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->dnsServerRepository->findByName($name);
|
|
});
|
|
}
|
|
}
|