perf: 温区缓存改多周期槽——切周期(2y/5y/10y)不互踢,各周期各自缓存
This commit is contained in:
@@ -41,7 +41,7 @@ def _chk_tcp(host, port, timeout=3):
|
||||
|
||||
# ── 2026-08-15 温区数据按周期计算 + 缓存(现场温区归因约30秒/请求,缓存后毫秒级)──
|
||||
# 键 = period_tag + strategy_research 最新 created_at(数据更新即失效)
|
||||
_regime_winrates_cache = {"key": None, "pt": None, "data": None}
|
||||
_regime_winrates_cache = {"key": None, "slots": {}} # slots: {period_tag: data}
|
||||
|
||||
|
||||
def _compute_regime_winrates_cached(pt, _approx_univ):
|
||||
@@ -61,8 +61,8 @@ def _compute_regime_winrates_cached(pt, _approx_univ):
|
||||
except Exception:
|
||||
_cache_key = None
|
||||
if _cache_key and _regime_winrates_cache.get("key") == _cache_key \
|
||||
and _regime_winrates_cache.get("pt") == (pt or "2y"):
|
||||
return _regime_winrates_cache.get("data") or {}
|
||||
and (pt or "2y") in (_regime_winrates_cache.get("slots") or {}):
|
||||
return _regime_winrates_cache["slots"][pt or "2y"]
|
||||
|
||||
_pt_chain = {'1m': '1y', '6m': '1y', '1y': '1y', '2y': '2y', '5y': '5y', '10y': '10y'}
|
||||
_pt_use = _pt_chain.get(pt or '2y', '2y')
|
||||
@@ -169,8 +169,7 @@ def _compute_regime_winrates_cached(pt, _approx_univ):
|
||||
if _cache_key:
|
||||
try:
|
||||
_regime_winrates_cache["key"] = _cache_key
|
||||
_regime_winrates_cache["pt"] = pt or "2y"
|
||||
_regime_winrates_cache["data"] = _regime_winrates
|
||||
(_regime_winrates_cache.setdefault("slots", {}))[pt or "2y"] = _regime_winrates
|
||||
except Exception:
|
||||
pass
|
||||
return _regime_winrates
|
||||
|
||||
Reference in New Issue
Block a user