HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/cachelib/__pycache__/simple.cpython-310.pyc
o

!we�
�@s@ddlZddlmZddlmZddlmZGdd�de�ZdS)�N)�time)�	BaseCache)�SimpleSerializerc
@seZdZdZe�Z		d$dedefdd�Zdefd	d
�Z	de
ddfd
d�Zd%dd�Zd%dd�Z
dejedefdd�Zdedejfdd�Z	d&dedejdejedejefdd�Zd&dedejdejedefdd�Zdedefdd�Zdedefd d!�Zdefd"d#�ZdS)'�SimpleCachea�Simple memory cache for single process environments.  This class exists
    mainly for the development server and is not 100% thread safe.  It tries
    to use as many atomic operations as possible and no locks for simplicity
    but it could happen under heavy load that keys are added multiple times.

    :param threshold: the maximum number of items the cache stores before
                      it starts deleting some.
    :param default_timeout: the default timeout that is used if no timeout is
                            specified on :meth:`~BaseCache.set`. A timeout of
                            0 indicates that the cache never expires.
    ���,�	threshold�default_timeoutcCs t�||�i|_|pd|_dS)Nr)r�__init__�_cache�
_threshold)�selfrr	�r�H/home/arjun/projects/env/lib/python3.10/site-packages/cachelib/simple.pyr
szSimpleCache.__init__�returncCst|j�|jkS�N)�lenrr�r
rrr�_over_threshold!szSimpleCache._over_threshold�nowNcs4�fdd�|j��D�}|D]	}|j�|d�qdS)Ncs g|]\}\}}|�kr|�qSrr)�.0�k�expires�_�rrr�
<listcomp>%s z/SimpleCache._remove_expired.<locals>.<listcomp>)r�items�pop)r
r�toremoverrrr�_remove_expired$s�zSimpleCache._remove_expiredcCsJdd�t|j��dd�d�D�}|D]}|j�|d�|��s"dSqdS)Ncss�|]\}}|VqdSrr)rr�vrrr�	<genexpr>*s
��
�z,SimpleCache._remove_older.<locals>.<genexpr>cSs|ddS)N�rr)�itemrrr�<lambda>-sz+SimpleCache._remove_older.<locals>.<lambda>)�key)�sortedrrrr)r
�	k_orderedrrrr�
_remove_older)s����zSimpleCache._remove_oldercCs0|��rt�}|�|�|��r|��dSdSr)rrrr()r
rrrr�_prune5s
�zSimpleCache._prune�timeoutcCs&t�||�}|dkrtt��|}|S�Nr)r�_normalize_timeout�intr)r
r*rrrr,=szSimpleCache._normalize_timeoutr%cCsJz|j|\}}|dks|t�kr|j�|�WSWdSty$YdSwr+)rr�
serializer�loads�KeyError�r
r%r�valuerrr�getCs��zSimpleCache.getr2cCs,|�|�}|��||j�|�f|j|<dS)NT)r,r)r.�dumpsr)r
r%r2r*rrrr�setKs
zSimpleCache.setcCsB|�|�}|��||j�|�f}||jvrdS|j�||�dS)NFT)r,r)r.r4r�
setdefault)r
r%r2r*rr#rrr�addSs

zSimpleCache.addcCs|j�|d�duSr)rr)r
r%rrr�delete\szSimpleCache.deletecCs<z|j|\}}t|dkp|t�k�WStyYdSw)NrF)r�boolrr0r1rrr�has_s�zSimpleCache.hascCs|j��t|j�Sr)r�clearr9rrrrr;fs
zSimpleCache.clear)rr)rNr)�__name__�
__module__�__qualname__�__doc__rr.r-r
r9r�floatrr(r)�_t�Optionalr,�str�Anyr3r5r7r8r:r;rrrrrs<��
�	

	����
�$	r)�typingrAr�
cachelib.baser�cachelib.serializersrrrrrr�<module>s