Files
portal-api/app/Repositories/Customer/CustomerCachedRepository.php

59 lines
2.1 KiB
PHP

<?php
namespace App\Repositories\Customer;
use App\Repositories\BaseCachedRepository;
use App\Support\Cache\CacheKey;
class CustomerCachedRepository extends BaseCachedRepository implements CustomerRepositoryInterface
{
public function __construct(
public CustomerRepository $customerRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->customerRepository->getModel();
}
public function filter(
array $data = [],
array $relationships = [],
array $withCount = [],
array $select = ['*'],
bool $returnQuery = false
) {
if (
$returnQuery ||
!empty($data['paginate'])
) {
return $this->customerRepository
->filter($data, $relationships, $withCount, $select, $returnQuery);
}
return $this->rememberFilter(
compact('data', 'relationships', 'withCount', 'select'),
fn() => $this->customerRepository->filter($data, $relationships, $withCount, $select, $returnQuery)
);
}
public function findWithRelationships(int $id = 0, array $relationships = [], array $withCount = [], array $withSum = [])
{
$cacheKey = CacheKey::build($this->getModuleName(), 'find-with-relationships', ['id' => $id]);
return $this->cache->remember($cacheKey, function () use ($id, $relationships, $withCount, $withSum) {
return $this->customerRepository->findWithRelationships($id, $relationships, $withCount, $withSum);
});
}
public function findBy(string $key = '', string $value = '')
{
$cacheKey = CacheKey::build($this->getModuleName(), 'find-by', ['key' => $key, 'value' => $value]);
return $this->cache->remember($cacheKey, function () use ($key, $value) {
return $this->customerRepository->findBy($key, $value);
});
}
public function onlyTrashed(array $relationships = [], array $withCount = [])
{
return $this->customerRepository->onlyTrashed($relationships, $withCount);
}
}