o
    h                     @  sX   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 deZdS )	    )annotations)TYPE_CHECKING)TTLCache)SessionInfoSessionStorage)MutableMappingc                   @  sH   e Zd ZdZ		ddd	d
ZdddZdddZdddZdddZdS ) 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.
       x   maxsizeintttl_secondsreturnNonec                 C  s   t ||d| _dS )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.
        )r   ttlN)r   _cache)selfr   r    r   \/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/runtime/memory_session_storage.py__init__)   s   zMemorySessionStorage.__init__
session_idstrSessionInfo | Nonec                 C  s   | j |d S N)r   getr   r   r   r   r   r   C      zMemorySessionStorage.getsession_infor   c                 C  s   || j |jj< d S r   )r   sessionid)r   r   r   r   r   saveF   s   zMemorySessionStorage.savec                 C  s   | j |= d S r   )r   r   r   r   r   deleteI   s   zMemorySessionStorage.deletelist[SessionInfo]c                 C  s   t | j S r   )listr   values)r   r   r   r   r#   L   r   zMemorySessionStorage.listN)r	   r
   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   )r   r"   )	__name__
__module____qualname____doc__r   r   r    r!   r#   r   r   r   r   r      s    


r   N)
__future__r   typingr   
cachetoolsr   !streamlit.runtime.session_managerr   r   collections.abcr   r   r   r   r   r   <module>   s   