ConfigCore.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Controllers;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using dodohold.core;
  9. using System.Xml.Linq;
  10. namespace molilian.core
  11. {
  12. public partial class TkConfigCore
  13. {
  14. private static readonly object _lockObj = new();
  15. private static TkConfigDTO _cached;
  16. public static TkConfigDTO Get(bool force = false)
  17. {
  18. if (!force && _cached != null) return _cached;
  19. string cache_key = $"cache:tk_config";
  20. var item = RedisHelper.Get<TkConfigDTO>(cache_key);
  21. if (force || item == null)
  22. {
  23. lock (_lockObj)
  24. {
  25. item = new DBContext.Table("tk_config").Get<TkConfigDTO>("id>0", new { });
  26. if (item == null) return default;
  27. RedisHelper.Set(cache_key, item, 30 * 86400);
  28. }
  29. }
  30. _cached = item;
  31. return item;
  32. }
  33. public static void Update(string ignorePercentageCity)
  34. {
  35. new DBContext.Table("tk_config")
  36. .Add("ignorePercentageCity", ignorePercentageCity)
  37. .Update();
  38. _ = Get(true);
  39. }
  40. public static void Update(int ignorePercentage)
  41. {
  42. new DBContext.Table("tk_config")
  43. .Add("ignorePercentage", ignorePercentage)
  44. .Update();
  45. _ = Get(true);
  46. }
  47. public static void JdUpdate(int ignorePercentage)
  48. {
  49. new DBContext.Table("tk_config")
  50. .Add("jdIgnorePercentage", ignorePercentage)
  51. .Update();
  52. _ = Get(true);
  53. }
  54. public static void Refresh()
  55. {
  56. _ = Get(true);
  57. }
  58. }
  59. }