
    h^                     F    S SK rS SKJr  S SKJr  S SKJr   " S S\5      rg)    N)time)	BaseCache)SimpleSerializerc            
          \ rS rSrSr\" 5       r  SS\S\4S jjrS\	4S jr
S\SS	4S
 jrSS jrSS jrS\R                   \   S\4S jrS\S\R&                  4S jr SS\S\R&                  S\R                   \   S\R                   \	   4S jjrSS\S\R&                  S\R                   \   S\	4S jjrS\S\	4S jrS\S\	4S jrS\	4S jrSrg	)SimpleCache   ak  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_timeoutc                 ^    [         R                  " X5        0 U l        U=(       d    SU l        g )N  )r   __init___cache
_threshold)selfr	   r
   s      dC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\cachelib/simple.pyr   SimpleCache.__init__   s%    
 	41,.#*s    returnc                 F    [        U R                  5      U R                  :  $ N)lenr   r   r   s    r   _over_thresholdSimpleCache._over_threshold    s    4;;$//11r   nowNc                     U R                   R                  5        VVVs/ s H  u  nu  p4X1:  d  M  UPM     nnnnU H  nU R                   R                  US 5        M!     g s  snnnf r   )r   itemspop)r   r   kexpires_toremoves         r   _remove_expiredSimpleCache._remove_expired#   sQ    -1[[->->-@R-@/!\gGMA-@RAKKOOAt$  Ss
   A!A!c                     S [        U R                  R                  5       S S9 5       nU H6  nU R                  R                  US 5        U R	                  5       (       a  M6    g    g )Nc              3   *   #    U  H	  u  pUv   M     g 7fr    ).0r   vs      r   	<genexpr>,SimpleCache._remove_older.<locals>.<genexpr>)   s      
R$!ARs   c                     U S   S   $ )N   r   r'   )items    r   <lambda>+SimpleCache._remove_older.<locals>.<lambda>*   s    tAwqzr   )key)sortedr   r   r   r   )r   	k_orderedr   s      r   _remove_olderSimpleCache._remove_older(   sV    
 !2!2!4:QR
	 AKKOOAt$'')) r   c                     U R                  5       (       a  [        5       nU R                  U5        U R                  5       (       a  U R                  5         g g r   )r   r   r#   r4   )r   r   s     r   _pruneSimpleCache._prune1   sF    !!&C  %!!  "r   timeoutc                 j    [         R                  " X5      nUS:  a  [        [        5       5      U-   nU$ Nr   )r   _normalize_timeoutintr   )r   r9   s     r   r<   SimpleCache._normalize_timeout9   s.    ..t=Q;$&kG+Gr   r1   c                      U R                   U   u  p#US:X  d  U[        5       :  a  U R                  R                  U5      $ g ! [         a     g f = fr;   )r   r   
serializerloadsKeyErrorr   r1   r    values       r   getSimpleCache.get?   sS    	![[-NG!|w/,,U33  0 		s   ?A 
AArD   c                     U R                  U5      nU R                  5         X@R                  R                  U5      4U R                  U'   g)NT)r<   r7   r@   dumpsr   )r   r1   rD   r9   r    s        r   setSimpleCache.setG   s@     ))'2#__%:%:5%ABCr   c                     U R                  U5      nU R                  5         X@R                  R                  U5      4nXR                  ;   a  gU R                  R                  X5        g)NFT)r<   r7   r@   rH   r   
setdefault)r   r1   rD   r9   r    r.   s         r   addSimpleCache.addO   sT    ))'2..u56++s)r   c                 >    U R                   R                  US 5      S L$ r   )r   r   )r   r1   s     r   deleteSimpleCache.deleteX   s    {{sD)55r   c                      U R                   U   u  p#[        US:H  =(       d    U[        5       :  5      $ ! [         a     gf = f)Nr   F)r   boolr   rB   rC   s       r   hasSimpleCache.has[   sD    	![[-NG18$&(899 		s   25 
AAc                 j    U R                   R                  5         [        U R                   5      (       + $ r   )r   clearrS   r   s    r   rW   SimpleCache.clearb   s$    $$$r   )r   r   )r   i,  )r   Nr   )__name__
__module____qualname____firstlineno____doc__r   r@   r=   r   rS   r   floatr#   r4   r7   _tOptionalr<   strAnyrE   rI   rM   rP   rT   rW   __static_attributes__r'   r   r   r   r      s/   
 "#J "++ +2 2%5 %T %
!"++c*: s s rvv  DH!vv02C0@	T	s 266 BKK4D PT 6# 6$ 6s t %t %r   r   )typingr_   r   cachelib.baser   cachelib.serializersr   r   r'   r   r   <module>rg      s      # 1\%) \%r   