|
|
@@ -17,9 +17,10 @@ namespace molilian.core
|
|
|
|
|
|
private static readonly object _lockObj = new();
|
|
|
private static IEnumerable<ProxyNodesDTO> _cached;
|
|
|
- public static string GetSelectOne(string node)
|
|
|
+ private static IEnumerable<ProxyNodesDTO> _all_cached;
|
|
|
+ public static string GetSelectOne(string node, bool all_node = false)
|
|
|
{
|
|
|
- var list = List();
|
|
|
+ var list = all_node ? AllList() : List();
|
|
|
if (!list.Any()) return null;
|
|
|
if (!node.Contains(",")) return node;
|
|
|
|
|
|
@@ -40,9 +41,9 @@ namespace molilian.core
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static WebProxy? GetOne(string node)
|
|
|
+ public static WebProxy? GetOne(string node, bool all_node = false)
|
|
|
{
|
|
|
- var list = List();
|
|
|
+ var list = all_node ? AllList() : List();
|
|
|
if (!list.Any()) return null;
|
|
|
|
|
|
// 处理包含逗号的节点参数
|
|
|
@@ -158,9 +159,31 @@ namespace molilian.core
|
|
|
_cached = list;
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ public static IEnumerable<ProxyNodesDTO> AllList(bool force = false)
|
|
|
+ {
|
|
|
+ if (!force && _all_cached != null) return _all_cached;
|
|
|
+
|
|
|
+ string cache_key = $"cache:all_proxy_nodes";
|
|
|
+ var list = RedisHelper.Get<IEnumerable<ProxyNodesDTO>>(cache_key);
|
|
|
+ if (force || list == null)
|
|
|
+ {
|
|
|
+ lock (_lockObj)
|
|
|
+ {
|
|
|
+ list = new DBContext.Table("proxy_nodes")
|
|
|
+ .Where("", new { status = 1 })
|
|
|
+ .Select<ProxyNodesDTO>();
|
|
|
+ if (list == null) return default;
|
|
|
+ RedisHelper.Set(cache_key, list, 30 * 86400);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ _all_cached = list;
|
|
|
+ return list;
|
|
|
+ }
|
|
|
public static void Refresh()
|
|
|
{
|
|
|
_ = List(true);
|
|
|
+ _ = AllList(true);
|
|
|
}
|
|
|
|
|
|
}
|