This commit is contained in:
@@ -35,11 +35,15 @@ class ThemeConfigModel
|
||||
public function getConfig(): array
|
||||
{
|
||||
// 尝试从缓存获取
|
||||
$config = Cache::get(self::CACHE_KEY);
|
||||
|
||||
if ($config !== false && $config !== null) {
|
||||
// 缓存命中
|
||||
return $config;
|
||||
try {
|
||||
$config = Cache::get(self::CACHE_KEY);
|
||||
|
||||
if ($config !== false && $config !== null) {
|
||||
// 缓存命中
|
||||
return $config;
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// 缓存系统异常,继续从数据库读取
|
||||
}
|
||||
|
||||
// 缓存未命中,从数据库读取
|
||||
@@ -51,8 +55,12 @@ class ThemeConfigModel
|
||||
$config = is_array($config) ? $config : $this->defaultConfig();
|
||||
}
|
||||
|
||||
// 写入缓存
|
||||
Cache::set(self::CACHE_KEY, $config, self::CACHE_TTL);
|
||||
// 写入缓存 (忽略缓存写入失败)
|
||||
try {
|
||||
Cache::set(self::CACHE_KEY, $config, self::CACHE_TTL);
|
||||
} catch (\Throwable $e) {
|
||||
// 忽略缓存写入失败
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
@@ -76,7 +84,11 @@ class ThemeConfigModel
|
||||
}
|
||||
|
||||
// 清除缓存,确保下次读取最新数据
|
||||
Cache::delete(self::CACHE_KEY);
|
||||
try {
|
||||
Cache::delete(self::CACHE_KEY);
|
||||
} catch (\Throwable $e) {
|
||||
// 忽略缓存删除失败
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user