|
@@ -7,32 +7,43 @@ namespace Hotline.CacheManager
|
|
|
{
|
|
|
public class CallCacheManager:ICallCacheManager, IScopeDependency
|
|
|
{
|
|
|
- private readonly ITypedCache<IReadOnlyList<Call>> _cacheCall;
|
|
|
+ private readonly ITypedCache<List<Call>> _cacheCall;
|
|
|
private const string CallKey = "CallQueue";
|
|
|
|
|
|
- public CallCacheManager(ITypedCache<IReadOnlyList<Call>> cacheCall)
|
|
|
+ public CallCacheManager(ITypedCache<List<Call>> cacheCall)
|
|
|
{
|
|
|
_cacheCall = cacheCall;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 获取队列
|
|
|
+ /// 新增或修改队列
|
|
|
/// </summary>
|
|
|
- /// <returns></returns>
|
|
|
- public IReadOnlyList<Call> GetCallQueueList()
|
|
|
+ /// <param name="list"></param>
|
|
|
+ public void AddCallCache(Call call)
|
|
|
{
|
|
|
- return _cacheCall.Get(CallKey)??new List<Call>();
|
|
|
+ var list = GetCallQueueList();
|
|
|
+ if (list == null)
|
|
|
+ {
|
|
|
+ list = new List<Call>();
|
|
|
+ }
|
|
|
+ list.Add(call);
|
|
|
+ _cacheCall.AddOrUpdate(CallKey, list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 新增或修改队列
|
|
|
+ /// 获取队列
|
|
|
/// </summary>
|
|
|
- /// <param name="list"></param>
|
|
|
- public void AddOrUpdateCallCache(List<Call> list)
|
|
|
+ /// <returns></returns>
|
|
|
+ public List<Call>? GetCallQueueList()
|
|
|
{
|
|
|
- _cacheCall.AddOrUpdate(CallKey, list);
|
|
|
+ var list = _cacheCall.GetOrAdd(CallKey, k =>
|
|
|
+ {
|
|
|
+ return new List<Call>();
|
|
|
+ });
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 删除队列
|
|
|
/// </summary>
|
|
@@ -41,13 +52,13 @@ namespace Hotline.CacheManager
|
|
|
public void RemoveCallCache(string id)
|
|
|
{
|
|
|
var list = _cacheCall.Get(CallKey)?.ToList();
|
|
|
- if (list!=null)
|
|
|
+ if (list != null)
|
|
|
{
|
|
|
- var model = list.First(x=>x.Id == id);
|
|
|
- if (model!=null)
|
|
|
+ var model = list.FirstOrDefault(x => x.Id == id);
|
|
|
+ if (model != null)
|
|
|
{
|
|
|
list.Remove(model);
|
|
|
- _cacheCall.AddOrUpdate(CallKey,list);
|
|
|
+ _cacheCall.AddOrUpdate(CallKey, list);
|
|
|
}
|
|
|
}
|
|
|
}
|