| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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<TkConfigDTO>(cache_key);
- if (force || item == null)
- {
- lock (_lockObj)
- {
- item = new DBContext.Table("tk_config").Get<TkConfigDTO>("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()
- {
- _ = Get(true);
- }
- }
- }
|