Files
portal-api/app/Repositories/Ticket/TicketCachedRepository.php
T
2025-07-24 16:18:27 +07:00

67 lines
2.4 KiB
PHP

<?php
namespace App\Repositories\Ticket;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class TicketCachedRepository extends BaseCachedRepository implements TicketRepositoryInterface
{
public function __construct(
public TicketRepository $ticketRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->ticketRepository->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->ticketRepository->filter($data, $relationships, $withCount, $select);
});
}
public function findWithRelationshipsByKey(string $key = '', string|int $value = '', array $relationships = [], array $withCount = [], array $withSum = [])
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'findWithRelationshipsByKey' => [
'key' => $key,
'value' => $value,
'relationships' => $relationships,
'withCount' => $withCount,
'withSum' => $withSum,
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value, $relationships, $withCount, $withSum) {
return $this->ticketRepository->findWithRelationshipsByKey($key, $value, $relationships, $withCount, $withSum);
});
}
public function findBy(string $key = '', string $value)
{
$cacheKey = $this->getCacheKey(md5(json_encode([
'findBy' => [
'key' => $key,
'value' => $value
]
])));
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
return $this->ticketRepository->findBy($key, $value);
});
}
public function updateBy(string $key = '', string $value = '', array $data = [])
{
$this->ticketRepository->updateBy($key, $value, $data);
$this->clearCache();
return $this;
}
}