From 7e38fd62577903372ee25709ceb378129a2fec45 Mon Sep 17 00:00:00 2001 From: OpenSquared Date: Wed, 17 Jun 2026 21:21:25 +0200 Subject: [PATCH] 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 --- backend/services/auto_cycle.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/services/auto_cycle.py b/backend/services/auto_cycle.py index 019f925..b5951ec 100644 --- a/backend/services/auto_cycle.py +++ b/backend/services/auto_cycle.py @@ -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}")