[fix]修正普通可空字段遇到并行冲突问题,改为并行字段
This commit is contained in:
parent
5124293ddb
commit
45f9b41d4e
|
@ -1,5 +1,5 @@
|
||||||
using NewLife.Caching;
|
using System.Collections.Concurrent;
|
||||||
using NewLife.Collections;
|
using NewLife.Caching;
|
||||||
|
|
||||||
namespace NewLife.Cube;
|
namespace NewLife.Cube;
|
||||||
|
|
||||||
|
@ -24,12 +24,52 @@ public class SessionProvider
|
||||||
Cache.SetExpire(sessionKey, Expire);
|
Cache.SetExpire(sessionKey, Expire);
|
||||||
|
|
||||||
//!! 临时修正可空字典的BUG
|
//!! 临时修正可空字典的BUG
|
||||||
if (Cache is MemoryCache mc && dic is not NullableDictionary<String, Object>)
|
if (Cache is MemoryCache mc && dic is not NullableDictionary2<String, Object>)
|
||||||
{
|
{
|
||||||
dic = new NullableDictionary<String, Object>(dic, StringComparer.Ordinal);
|
dic = new NullableDictionary2<String, Object>(dic, StringComparer.Ordinal);
|
||||||
mc.Set(sessionKey, dic);
|
mc.Set(sessionKey, dic);
|
||||||
}
|
}
|
||||||
|
|
||||||
return dic;
|
return dic;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>可空字典。获取数据时如果指定键不存在可返回空而不是抛出异常</summary>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
/// <typeparam name="TValue"></typeparam>
|
||||||
|
class NullableDictionary2<TKey, TValue> : ConcurrentDictionary<TKey, TValue>, IDictionary<TKey, TValue> where TKey : notnull
|
||||||
|
{
|
||||||
|
/// <summary>实例化一个可空字典</summary>
|
||||||
|
public NullableDictionary2() { }
|
||||||
|
|
||||||
|
/// <summary>指定比较器实例化一个可空字典</summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public NullableDictionary2(IEqualityComparer<TKey> comparer) : base(comparer) { }
|
||||||
|
|
||||||
|
/// <summary>实例化一个可空字典</summary>
|
||||||
|
/// <param name="dic"></param>
|
||||||
|
public NullableDictionary2(IDictionary<TKey, TValue> dic) : base(dic) { }
|
||||||
|
|
||||||
|
/// <summary>实例化一个可空字典</summary>
|
||||||
|
/// <param name="dic"></param>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public NullableDictionary2(IDictionary<TKey, TValue> dic, IEqualityComparer<TKey> comparer) : base(dic, comparer) { }
|
||||||
|
|
||||||
|
/// <summary>获取 或 设置 数据</summary>
|
||||||
|
/// <param name="item"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public new TValue this[TKey item]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (TryGetValue(item, out var v)) return v;
|
||||||
|
|
||||||
|
return default!;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
base[item] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue