Browse Source

callcache

dss 2 years ago
parent
commit
4b5aa08834
2 changed files with 25 additions and 75 deletions
  1. 25 14
      src/Hotline.CacheManager/CallCacheManager.cs
  2. 0 61
      src/Hotline/Caches/CallCacheManager.cs

+ 25 - 14
src/Hotline.CacheManager/CallCacheManager.cs

@@ -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);
                 }
             }
         }

+ 0 - 61
src/Hotline/Caches/CallCacheManager.cs

@@ -1,61 +0,0 @@
-using Hotline.CallCenter.Calls;
-using XF.Domain.Cache;
-using XF.Domain.Dependency;
-
-namespace Hotline.Caches
-{
-    public class CallCacheManager:ICallCacheManager, IScopeDependency
-    {
-        private readonly ITypedCache<List<Call>> _cacheCall;
-        private const string CallKey = "CallQueue";
-
-        public CallCacheManager(ITypedCache<List<Call>> cacheCall)
-        {
-            _cacheCall = cacheCall;
-        }
-
-        /// <summary>
-        /// 获取队列
-        /// </summary>
-        /// <returns></returns>
-        public List<Call>? GetCallQueueList()
-        {
-            var list = _cacheCall.GetOrAdd(CallKey, k =>
-            {
-                return new List<Call>();
-            });
-            return list;
-        }
-
-        
-        public void AddCallCache(Call call)
-        {
-            var list = GetCallQueueList();
-            if (list==null)
-            {
-                list = new List<Call>();
-            }
-            list.Add(call);
-            _cacheCall.AddOrUpdate(CallKey, list);
-        }
-
-        /// <summary>
-        /// 删除队列
-        /// </summary>
-        /// <param name="id"></param>
-        /// <exception cref="NotImplementedException"></exception>
-        public void RemoveCallCache(string id)
-        {
-            var list = _cacheCall.Get(CallKey)?.ToList();
-            if (list!=null)
-            {
-                var model = list.First(x=>x.Id == id);
-                if (model!=null)
-                {
-                    list.Remove(model);
-                    _cacheCall.AddOrUpdate(CallKey,list);
-                }
-            }
-        }
-    }
-}