
    i(                     2    d Z ddlZddlmZ  G d de      Zy)zK
Add the event loop to the cache key, to prevent event loop closed errors.
    N   )InMemoryCachec                   F     e Zd ZdZd Z fdZ fdZ fdZ fdZ xZ	S )LLMClientCachea  Cache for LLM HTTP clients (OpenAI, Azure, httpx, etc.).

    IMPORTANT: This cache intentionally does NOT close clients on eviction.
    Evicted clients may still be in use by in-flight requests. Closing them
    eagerly causes ``RuntimeError: Cannot send a request, as the client has
    been closed.`` errors in production after the TTL (1 hour) expires.

    Clients that are no longer referenced will be garbage-collected normally.
    For explicit shutdown cleanup, use ``close_litellm_async_clients()``.
    c                     	 t        j                         }t        t        |            }| d| S # t        $ r |cY S w xY w)z
        Add the event loop to the cache key, to prevent event loop closed errors.
        If none, use the key as is.
        -)asyncioget_running_loopstridRuntimeError)selfkey
event_loopstringified_event_loops       t/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/caching/llm_caching_handler.py update_cache_key_with_event_loopz/LLMClientCache.update_cache_key_with_event_loop   sK    
	 113J%(J%8"U!2344 	J	s   .1 ??c                 H    | j                  |      }t        |   ||fi |S N)r   super	set_cacher   r   valuekwargs	__class__s       r   r   zLLMClientCache.set_cache"   s*    33C8w e6v66    c                 d   K   | j                  |      }t        |   ||fi | d {   S 7 wr   )r   r   async_set_cacher   s       r   r   zLLMClientCache.async_set_cache&   s4     33C8W,S%B6BBBBs   &0.0c                 F    | j                  |      }t        |   |fi |S r   )r   r   	get_cacher   r   r   r   s      r   r    zLLMClientCache.get_cache*   s(    33C8w ///r   c                 b   K   | j                  |      }t        |   |fi | d {   S 7 wr   )r   r   async_get_cacher!   s      r   r#   zLLMClientCache.async_get_cache/   s2     33C8W,S;F;;;;s   %/-/)
__name__
__module____qualname____doc__r   r   r   r    r#   __classcell__)r   s   @r   r   r   
   s'    	
7C0
< <r   r   )r'   r	   in_memory_cacher   r    r   r   <module>r+      s     *(<] (<r   