Files
portal-api/app/Repositories/Module/IpAddress/IpAddressCachedRepository.php
T
2025-07-24 16:18:27 +07:00

64 lines
2.3 KiB
PHP

<?php
namespace App\Repositories\Module\IpAddress;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class IpAddressCachedRepository extends BaseCachedRepository implements IpAddressRepositoryInterface
{
public function __construct(
public IpAddressRepository $ipAddressRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->ipAddressRepository->getModel();
}
public function filter(array $data = [], array $relationships = [], array $withCount = [], array $select = ['*'])
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'filterItem' => [
'data' => $data,
'relationships' => $relationships,
'select' => $select,
'withCount' => $withCount
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($data, $relationships, $select, $withCount) {
return $this->ipAddressRepository->filter($data, $relationships, $withCount, $select);
});
}
public function updateBy(array $condistions = [], array $data = [])
{
$this->ipAddressRepository->updateBy($condistions, $data);
$this->clearCache();
return $this;
}
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->ipAddressRepository->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->ipAddressRepository->findBy($key, $value);
});
}
}