Files
portal-api/app/Repositories/Setting/SettingCachedRepository.php
2026-06-22 08:43:32 +07:00

38 lines
1.1 KiB
PHP

<?php
namespace App\Repositories\Setting;
use App\Repositories\BaseCachedRepository;
use Illuminate\Support\Facades\Cache;
class SettingCachedRepository extends BaseCachedRepository implements SettingRepositoryInterface
{
public function __construct(
public SettingRepository $settingRepository
) {
parent::__construct();
}
public function getModel()
{
return $this->settingRepository->getModel();
}
public function getByKey(string $key = '')
{
$cacheKey = $this->getCacheKey('setting_getByKey:'.$key);
return Cache::remember($cacheKey, $this->cacheTime, function () use ($key) {
return $this->settingRepository->getByKey($key);
});
}
public function updateOrCreateByKey(string $key, array $data = [])
{
$this->clearCacheByKey($key);
return $this->settingRepository->updateOrCreateByKey($key, $data);
}
public function clearCacheByKey(string $key): void
{
$cacheKey = $this->getCacheKey("setting_getByKey:{$key}");
Cache::forget($cacheKey);
}
}