APICacheManageController.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Net.Http;
  6. using System.Web.Http;
  7. using Lottomat.Application.Code;
  8. using Lottomat.Application.Entity.CommonEntity;
  9. using Lottomat.Application.Entity.LotteryNumberManage.Parameter;
  10. using Lottomat.Cache.Factory;
  11. using Lottomat.SOA.API.Controllers.Base;
  12. using Lottomat.Util.Extension;
  13. namespace Lottomat.SOA.API.Controllers.V1
  14. {
  15. /// <summary>
  16. /// API缓存管理
  17. /// </summary>
  18. public class APICacheManageController : BaseApiController
  19. {
  20. /// <summary>
  21. /// API缓存管理
  22. /// </summary>
  23. /// <returns></returns>
  24. [HttpPost]
  25. public HttpResponseMessage RemoveCacheByKey(RemoveCacheArgEntity arg)
  26. {
  27. BaseJson<string> resultMsg = new BaseJson<string> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  28. Logger(typeof(APICacheManageController), arg.TryToJson(), "API缓存管理-RemoveCacheByKey", () =>
  29. {
  30. if (!string.IsNullOrEmpty(arg.t))
  31. {
  32. if (arg.t.CheckTimeStamp())
  33. {
  34. if (!string.IsNullOrEmpty(arg.CacheKey))
  35. {
  36. string[] cacheKeys = arg.CacheKey.Split("|".ToCharArray());
  37. foreach (string key in cacheKeys)
  38. {
  39. CacheFactory.Cache().RemoveCache(key);
  40. }
  41. resultMsg = new BaseJson<string>
  42. {
  43. Status = (int)JsonObjectStatus.Success,
  44. Data = null,
  45. Message = JsonObjectStatus.Success.GetEnumText(),
  46. BackUrl = null
  47. };
  48. }
  49. }
  50. else
  51. {
  52. resultMsg = new BaseJson<string>
  53. {
  54. Status = (int)JsonObjectStatus.Fail,
  55. Data = null,
  56. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  57. BackUrl = null
  58. };
  59. }
  60. }
  61. else
  62. {
  63. resultMsg = new BaseJson<string>
  64. {
  65. Status = (int)JsonObjectStatus.Fail,
  66. Data = null,
  67. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  68. BackUrl = null
  69. };
  70. }
  71. }, e =>
  72. {
  73. resultMsg = new BaseJson<string>
  74. {
  75. Status = (int)JsonObjectStatus.Exception,
  76. Data = null,
  77. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  78. BackUrl = null
  79. };
  80. });
  81. return resultMsg.TryToJson().ToHttpResponseMessage();
  82. }
  83. }
  84. }