refactor: implement centralized cache key management and add utility traits for vCenter SSH operations.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace App\Repositories\Customer;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Support\Cache\CacheKey;
|
||||
|
||||
class CustomerCachedRepository extends BaseCachedRepository implements CustomerRepositoryInterface
|
||||
{
|
||||
@@ -31,39 +31,22 @@ class CustomerCachedRepository extends BaseCachedRepository implements CustomerR
|
||||
->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->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 = $this->getCacheKey(md5(json_encode([
|
||||
'findWithRelationships' => [
|
||||
'id' => $id,
|
||||
'relationships' => $relationships
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($id, $relationships, $withCount, $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 = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user