o
    ưi(                     @   s,   d Z ddlZddlmZ G dd deZdS )zK
Add the event loop to the cache key, to prevent event loop closed errors.
    N   )InMemoryCachec                       sL   e Zd ZdZdd Z fddZ fddZ fdd	Z fd
dZ  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                 C   s<   zt  }tt|}| d| W S  ty   | Y S 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keyZ
event_loopZstringified_event_loop r   Z/home/app/Keep/.python/lib/python3.10/site-packages/litellm/caching/llm_caching_handler.py update_cache_key_with_event_loop   s   z/LLMClientCache.update_cache_key_with_event_loopc                    s    |  |}t j||fi |S N)r   super	set_cacher   r   valuekwargs	__class__r   r   r   "   s   
zLLMClientCache.set_cachec                    s(   |  |}t j||fi |I d H S r   )r   r   async_set_cacher   r   r   r   r   &   s   
zLLMClientCache.async_set_cachec                    s   |  |}t j|fi |S r   )r   r   	get_cacher   r   r   r   r   r   r   *   s   
zLLMClientCache.get_cachec                    s&   |  |}t j|fi |I d H S r   )r   r   async_get_cacher   r   r   r   r   /   s   
zLLMClientCache.async_get_cache)
__name__
__module____qualname____doc__r   r   r   r   r   __classcell__r   r   r   r   r   
   s    r   )r   r   Zin_memory_cacher   r   r   r   r   r   <module>   s    