| 100 | |
| 101 | |
| 102 | async def handle_parameter_cache(req_id: str, context: RequestContext) -> None: |
| 103 | set_request_id(req_id) |
| 104 | logger = context["logger"] |
| 105 | params_cache_lock = context["params_cache_lock"] |
| 106 | page_params_cache = context["page_params_cache"] |
| 107 | current_ai_studio_model_id = context["current_ai_studio_model_id"] |
| 108 | model_actually_switched = context["model_actually_switched"] |
| 109 | |
| 110 | async with params_cache_lock: |
| 111 | cached_model_for_params = page_params_cache.get( |
| 112 | "last_known_model_id_for_params" |
| 113 | ) |
| 114 | if model_actually_switched or ( |
| 115 | current_ai_studio_model_id != cached_model_for_params |
| 116 | ): |
| 117 | logger.info(f"[{req_id}] Model changed, parameter cache invalidated.") |
| 118 | page_params_cache.clear() |
| 119 | page_params_cache["last_known_model_id_for_params"] = ( |
| 120 | current_ai_studio_model_id |
| 121 | ) |