63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Module\Host;
|
|
|
|
use App\Repositories\BaseCachedRepository;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class HostCachedRepository extends BaseCachedRepository implements HostRepositoryInterface
|
|
{
|
|
public function __construct(
|
|
public HostRepository $hostRepository
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
public function getModel()
|
|
{
|
|
return $this->hostRepository->getModel();
|
|
}
|
|
public function filter(
|
|
array $data = [],
|
|
array $relationships = [],
|
|
array $withCount = [],
|
|
array $select = ['*'],
|
|
bool $returnQuery = false
|
|
) {
|
|
if ($returnQuery || isset($data['page']) || isset($data['paginate'])) {
|
|
return $this->hostRepository->filter($data, $relationships, $withCount, $select, $returnQuery);
|
|
}
|
|
|
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
|
'filter' => compact('data', 'relationships', 'withCount', 'select')
|
|
])));
|
|
|
|
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount, $returnQuery) {
|
|
return $this->hostRepository->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->hostRepository->findWithRelationships($id, $relationships,$withCount,$withSum);
|
|
});
|
|
}
|
|
public function findBy(string $key = '', string|int|null $value = '')
|
|
{
|
|
$cacheKey = $this->getCacheKey(md5(json_encode([
|
|
'findBy' => [
|
|
'key' => $key,
|
|
'value' => $value
|
|
]
|
|
])));
|
|
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
|
return $this->hostRepository->findBy($key, $value);
|
|
});
|
|
}
|
|
}
|