fix: invalidate IV watchlist cache after cycle fetches fresh IV data
The auto-cycle was saving new IV snapshots to SQLite but not clearing the in-memory cache in options_vol.py (TTL 1h), so the Options Lab page kept showing stale IV Rank data until the cache naturally expired. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -348,6 +348,16 @@ def run_cycle_once(trigger: str = "auto") -> Dict[str, Any]:
|
||||
iv_context = get_iv_context_for_prompt(_iv_tickers)
|
||||
if iv_context:
|
||||
logger.info(f"[Cycle {run_id[:16]}] IV context collected for {len(_iv_tickers)} tickers")
|
||||
# Invalidate the options_vol watchlist cache so the frontend sees fresh data
|
||||
try:
|
||||
from routers.options_vol import _iv_cache
|
||||
stale_keys = [k for k in list(_iv_cache.keys()) if k.startswith("watchlist:") or k.startswith("snapshot:")]
|
||||
for k in stale_keys:
|
||||
_iv_cache.pop(k, None)
|
||||
if stale_keys:
|
||||
logger.info(f"[Cycle] IV cache invalidated ({len(stale_keys)} entries)")
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as _e:
|
||||
logger.warning(f"[Cycle] IV context collection failed (non-blocking): {_e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user