CacheService.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Common;
  2. namespace Services
  3. {
  4. public class CacheService
  5. {
  6. private readonly static string CK_verifyScan = "verifyScan_";
  7. private readonly static string CK_phoneSmsCode = "phone_sms_code_";
  8. #region 用户权限 缓存
  9. public static List<string> GetUserPerms(string key)
  10. {
  11. return (List<string>)CacheHelper.GetCache(key);
  12. //return RedisServer.Cache.Get<List<string>>(key).ToList();
  13. }
  14. public static void SetUserPerms(string key, object data)
  15. {
  16. CacheHelper.SetCache(key, data);
  17. //RedisServer.Cache.Set(key, data);
  18. }
  19. public static void RemoveUserPerms(string key)
  20. {
  21. CacheHelper.Remove(key);
  22. //RedisServer.Cache.Del(key);
  23. }
  24. #endregion
  25. public static object SetScanLogin(string key, Dictionary<string, object> val)
  26. {
  27. var ck = CK_verifyScan + key;
  28. return CacheHelper.SetCache(ck,val , 1);
  29. }
  30. public static object GetScanLogin(string key)
  31. {
  32. var ck = CK_verifyScan + key;
  33. return CacheHelper.Get(ck);
  34. }
  35. public static void RemoveScanLogin(string key)
  36. {
  37. var ck = CK_verifyScan + key;
  38. CacheHelper.Remove(ck);
  39. }
  40. public static void SetLockUser(string key, long val, int time)
  41. {
  42. var CK = "lock_user_" + key;
  43. CacheHelper.SetCache(CK, val, time);
  44. }
  45. public static long GetLockUser(string key)
  46. {
  47. var CK = "lock_user_" + key;
  48. if (CacheHelper.Get(CK) is long t)
  49. {
  50. return t;
  51. }
  52. return 0;
  53. }
  54. public static object SetPhoneCode(string key, string val)
  55. {
  56. var ck = CK_phoneSmsCode + key;
  57. return CacheHelper.SetCache(ck, val, 10);
  58. }
  59. public static bool CheckPhoneCode(string key, string val)
  60. {
  61. var ck = CK_phoneSmsCode + key;
  62. var save_code = CacheHelper.Get(ck);
  63. if (save_code != null && save_code.Equals(val))
  64. {
  65. return true;
  66. }
  67. return false;
  68. }
  69. }
  70. }