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\Discount;
|
||||
|
||||
use App\Repositories\BaseCachedRepository;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Support\Cache\CacheKey;
|
||||
|
||||
class DiscountCachedRepository extends BaseCachedRepository implements DiscountRepositoryInterface
|
||||
{
|
||||
@@ -18,32 +18,19 @@ class DiscountCachedRepository extends BaseCachedRepository implements DiscountR
|
||||
}
|
||||
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->discountRepository->filter($data, $relationships, $withCount, $select);
|
||||
});
|
||||
return $this->rememberFilter(
|
||||
compact('data', 'relationships', 'withCount', 'select'),
|
||||
fn() => $this->discountRepository->filter($data, $relationships, $withCount, $select)
|
||||
);
|
||||
}
|
||||
public function findBy(string $key = '', string $value = '')
|
||||
{
|
||||
$cacheKey = $this->getCacheKey(md5(json_encode([
|
||||
'findBy' => [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
]
|
||||
])));
|
||||
if (empty($value) || empty($key)) {
|
||||
return false;
|
||||
}
|
||||
return $this->model->where($key, $value)->first();
|
||||
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key, $value) {
|
||||
return $this->discountRepository->findBy($key, $value);
|
||||
$cacheKey = CacheKey::build($this->getModuleName(), 'find-by', ['key' => $key, 'value' => $value]);
|
||||
return $this->cache->remember($cacheKey, function () use ($key, $value) {
|
||||
return $this->model->where($key, $value)->first();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user