using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Collections.Generic; using System.Linq; using System.Text; using dodohold.core; using System.Xml.Linq; namespace molilian.core { public partial class TkConfigCore { private static readonly object _lockObj = new(); private static TkConfigDTO _cached; public static TkConfigDTO Get(bool force = false) { if (!force && _cached != null) return _cached; string cache_key = $"cache:tk_config"; var item = RedisHelper.Get(cache_key); if (force || item == null) { lock (_lockObj) { item = new DBContext.Table("tk_config").Get("id>0", new { }); if (item == null) return default; RedisHelper.Set(cache_key, item, 30 * 86400); } } _cached = item; return item; } public static void Update(string ignorePercentageCity) { new DBContext.Table("tk_config") .Add("ignorePercentageCity", ignorePercentageCity) .Update(); _ = Get(true); } public static void Update(int ignorePercentage) { new DBContext.Table("tk_config") .Add("ignorePercentage", ignorePercentage) .Update(); _ = Get(true); } public static void JdUpdate(int ignorePercentage) { new DBContext.Table("tk_config") .Add("jdIgnorePercentage", ignorePercentage) .Update(); _ = Get(true); } public static void Refresh() { _cached = null; _ = Get(true); } } }