Skip to content

Commit b4e4716

Browse files
committed
refactor: 增加 Lock 对象
1 parent 2b5bb92 commit b4e4716

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/BootstrapBlazor/Services/CacheManager.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ private static JsonLocalizationOptions GetJsonLocalizationOption()
210210
public static IEnumerable<LocalizedString>? GetAllStringsByTypeName(Assembly assembly, string typeName)
211211
=> GetJsonStringByTypeName(GetJsonLocalizationOption(), assembly, typeName, CultureInfo.CurrentUICulture.Name);
212212

213+
#if NET9_0_OR_GREATER
214+
private static readonly Lock _locker = new();
215+
#else
216+
private static readonly object _locker = new();
217+
#endif
218+
213219
/// <summary>
214220
/// 通过指定程序集获取所有本地化信息键值集合
215221
/// </summary>
@@ -234,7 +240,7 @@ private static JsonLocalizationOptions GetJsonLocalizationOption()
234240
Instance.Cache.Remove(key);
235241
}
236242

237-
lock (assembly)
243+
lock (_locker)
238244
{
239245
localizedItems = Instance.GetOrCreate(key, _ =>
240246
{

0 commit comments

Comments
 (0)