
    g                    ^    d dl mZ d dlmZ d dlmZ d dlmZmZ erd dl	m
Z
  G d de      Zy)	    )annotations)TYPE_CHECKING)TTLCache)SessionInfoSessionStorage)MutableMappingc                  H    e Zd ZdZ	 	 d	 	 	 	 	 d	dZd
dZddZddZddZy)MemorySessionStoragezA SessionStorage that stores sessions in memory.

    At most maxsize sessions are stored with a TTL of ttl seconds. This class is really
    just a thin wrapper around cachetools.TTLCache that complies with the SessionStorage
    protocol.
    c                (    t        ||      | _        y)a  Instantiate a new MemorySessionStorage.

        Parameters
        ----------
        maxsize
            The maximum number of sessions we allow to be stored in this
            MemorySessionStorage. If an entry needs to be removed because we have
            exceeded this number, either
            - an expired entry is removed, or
            - the least recently used entry is removed (if no entries have expired).

        ttl_seconds
            The time in seconds for an entry added to a MemorySessionStorage to live.
            After this amount of time has passed for a given entry, it becomes
            inaccessible and will be removed eventually.
        )maxsizettlN)r   _cache)selfr   ttl_secondss      ]/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/memory_session_storage.py__init__zMemorySessionStorage.__init__)   s    , 9A9
    c                :    | j                   j                  |d       S N)r   getr   
session_ids     r   r   zMemorySessionStorage.getC   s    {{z400r   c                J    || j                   |j                  j                  <   y r   )r   sessionid)r   session_infos     r   savezMemorySessionStorage.saveF   s    /;L((++,r   c                    | j                   |= y r   )r   r   s     r   deletezMemorySessionStorage.deleteI   s    KK
#r   c                H    t        | j                  j                               S r   )listr   values)r   s    r   r!   zMemorySessionStorage.listL   s    DKK&&())r   N)   x   )r   intr   r%   returnNone)r   strr&   zSessionInfo | None)r   r   r&   r'   )r   r(   r&   r'   )r&   zlist[SessionInfo])	__name__
__module____qualname____doc__r   r   r   r   r!    r   r   r
   r
      sD     !

 
 
	
41<$*r   r
   N)
__future__r   typingr   
cachetoolsr   !streamlit.runtime.session_managerr   r   collections.abcr   r
   r-   r   r   <module>r3      s%    #    I.2*> 2*r   