
    5i0                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
  ed      Z ed      Z G d	 d
eeef         Zy)zSLRU cache supporting TTL and max entry count, as well as release hooks for cleanup.    )Callable)TypeVar)TTLCache)override)	OnReleaseKVc            
            e Zd ZdZdededeg ef   deddf
 fdZede	e
ef   f fd	       Zedd
edz  dee	e
ef      f fd       Zde
ddfdZ xZS )TTLCleanupCachea,  A TTLCache that supports hooks called when items are released.

    Note that item release only happens reliably when done automatically due to TTL
    or maxsize expiration - and specifically does not happen when using ``del``. To
    remove an item and have on_release be called, use safe_del.
    maxsizettltimer
on_releasereturnNc                 8    t         |   |||       || _        y)a  Create a cache with the given size, TTL, and release hook.

        Parameters
        ----------
        maxsize : float
            The maximum number of elements this cache should hold.
        ttl : float
            The amount of time a cache entry should remain valid, in seconds.
        timer : Callable[[], float]
            The timer function to use to fetch the current time.
        on_release : OnRelease
            The function to call with cache entries when they are removed from the
            cache.
        )r   r   r   N)super__init___on_release)selfr   r   r   r   	__class__s        u/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/streamlit/runtime/caching/ttl_cleanup_cache.pyr   zTTLCleanupCache.__init__(   s!    * 	c?%    c                 P    t         |          \  }}| j                  |       ||fS N)r   popitemr   )r   keyvaluer   s      r   r   zTTLCleanupCache.popitem@   s+    W_&
UEzr   timec                 \    t         |   |      }|D ]  \  }}| j                  |        |S r   )r   expirer   )r   r   items_r   r   s        r   r    zTTLCleanupCache.expireF   s9    t$ 	$HAuU#	$ r   r   c                 \    || v }| j                  |      }| |= |r| j                  |       yy)zDelete that calls _on_release.N)getr   )r   r   	has_value	old_values       r   safe_delzTTLCleanupCache.safe_delN   s5    4K	HHSM	IY' r   r   )__name__
__module____qualname____doc__floatr   r   r   r   tupler   r	   r   listr    r'   __classcell__)r   s   @r   r   r       s    && & E	"	&
 & 
&0 q!t  
 54< 4ad3D  (A ($ (r   r   N)r+   collections.abcr   typingr   
cachetoolsr   typing_extensionsr   %streamlit.runtime.caching.cache_utilsr   r   r	   r    r   r   <module>r6      sB    Z $   ' ;CLCL5(hq!tn 5(r   