CallCacheManager.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Hotline.Caches;
  2. using Hotline.CallCenter.Calls;
  3. using XF.Domain.Cache;
  4. using XF.Domain.Dependency;
  5. namespace Hotline.CacheManager
  6. {
  7. public class CallCacheManager : ICallCacheManager, IScopeDependency
  8. {
  9. private readonly ITypedCache<List<Call>> _cacheCall;
  10. private const string CallKey = "CallQueue";
  11. public CallCacheManager(ITypedCache<List<Call>> cacheCall)
  12. {
  13. _cacheCall = cacheCall;
  14. }
  15. /// <summary>
  16. /// 新增或修改队列
  17. /// </summary>
  18. /// <param name="list"></param>
  19. public void AddCallCache(Call call)
  20. {
  21. var list = GetCallQueueList();
  22. if (list == null)
  23. {
  24. list = new List<Call>();
  25. }
  26. list.Add(call);
  27. _cacheCall.AddOrUpdate(CallKey, list);
  28. }
  29. /// <summary>
  30. /// 获取队列
  31. /// </summary>
  32. /// <returns></returns>
  33. public List<Call>? GetCallQueueList()
  34. {
  35. var list = _cacheCall.GetOrAdd(CallKey, k =>
  36. {
  37. return new List<Call>();
  38. });
  39. return list;
  40. }
  41. /// <summary>
  42. /// 删除队列
  43. /// </summary>
  44. /// <param name="id"></param>
  45. /// <exception cref="NotImplementedException"></exception>
  46. public void RemoveCallCache(string id)
  47. {
  48. var list = _cacheCall.Get(CallKey)?.ToList();
  49. if (list != null)
  50. {
  51. var model = list.FirstOrDefault(x => x.Id == id);
  52. if (model != null)
  53. {
  54. list.Remove(model);
  55. _cacheCall.AddOrUpdate(CallKey, list);
  56. }
  57. }
  58. }
  59. }
  60. }