
    Dg                         d Z ddlmZ  G d de          Z G d de          Z G d de          Z G d	 d
e          Z G d de          ZdS )z
This module contains multithread-safe cache implementations.

All Caches have

    getorbuild(key, builder)
    delentry(key)

methods and allow configuration when instantiating the cache class.
    )timec                   <    e Zd ZddZd Zd Zd ZddZd Zd	 Z	d
S )
BasicCache   c                 V    || _         t          ||dz  z
            | _        i | _        d S )N   )
maxentriesintprunenum_dict)selfr	   s     G/var/www/sysmax/venv/lib/python3.11/site-packages/py/_path/cacheutil.py__init__zBasicCache.__init__   s,    $JA566


    c                 8    | j                                          d S N)r   clearr   s    r   r   zBasicCache.clear   s    
r   c                     | j         |         S r   )r   )r   keys     r   	_getentryzBasicCache._getentry   s    z#r   c                 B    |                                   || j        |<   d S r   )_prunelowestweightr   r   r   entrys      r   	_putentryzBasicCache._putentry   s#    !!!
3r   Fc                 @    	 | j         |= d S # t          $ r |r Y d S w xY wr   )r   KeyError)r   r   raisings      r   delentryzBasicCache.delentry   sI    	
3 	 	 	   	s    c                     	 |                      |          }n<# t          $ r/ |                     ||          }|                     ||           Y nw xY w|j        S r   )r   r   _buildr   value)r   r   builderr   s       r   
getorbuildzBasicCache.getorbuild$   sl    	'NN3''EE 	' 	' 	'KKW--ENN3&&&&&	' {s    6AAc                 (   t          | j                  }|| j        k    rnd | j                                        D             }|                                 || j        z
  }|dk    r)|d|         D ] \  }}|                     |d           dS dS dS )z' prune out entries with lowest weight. c                 &    g | ]\  }}|j         |fS  )weight).0r   r   s      r   
<listcomp>z1BasicCache._prunelowestweight.<locals>.<listcomp>1   s3     > > >&C lC( > > >r   r   NF)r   )lenr   r	   itemssortr   r    )r   
numentriesr-   indexr)   r   s         r   r   zBasicCache._prunelowestweight,   s    __
((> >*.**:*:*<*<> > >EJJLLL.Eqyy#(%= 6 6KFCMM#uM5555 )( y6 6r   N)r   )F)
__name__
__module____qualname__r   r   r   r   r    r%   r   r(   r   r   r   r      s           
              6 6 6 6 6r   r   c                       e Zd ZdZd ZdS )BuildcostAccessCachea   A BuildTime/Access-counting cache implementation.
        the weight of a value is computed as the product of

            num-accesses-of-a-value * time-to-build-the-value

        The values with the least such weights are evicted
        if the cache maxentries threshold is superceded.
        For implementation flexibility more than one object
        might be evicted at a time.
    c                 t    t                      } |            }t                      }t          |||z
            S r   )gettimeWeightedCountingEntry)r   r   r$   startvalends         r   r"   zBuildcostAccessCache._buildG   s3    		giiii$S#e)444r   N)r1   r2   r3   __doc__r"   r(   r   r   r5   r5   :   s-        	 	5 5 5 5 5r   r5   c                   0    e Zd Zd Zd Z ee          ZdS )r8   c                 0    || _         |x| _        | _        d S r   )_valuer)   
_oneweight)r   r#   	oneweights      r   r   zWeightedCountingEntry.__init__O   s    (11dooor   c                 :    | xj         | j        z  c_         | j        S r   )r)   r@   r?   r   s    r   r#   zWeightedCountingEntry.valueS   s    t&{r   N)r1   r2   r3   r   r#   propertyr(   r   r   r8   r8   N   s;        2 2 2   HUOOEEEr   r8   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )
AgingCachez; This cache prunes out cache entries that are too old.
    r         $@c                 f    t          t          |                               |           || _        d S r   )superrE   r   
maxseconds)r   r	   rI   	__class__s      r   r   zAgingCache.__init__[   s,    j$((444$r   c                     | j         |         }|                                r$|                     |           t          |          |S r   )r   	isexpiredr    r   r   s      r   r   zAgingCache._getentry_   sB    
3?? 	 MM#3--r   c                 b     |            }t          |t                      | j        z             }|S r   )
AgingEntryr7   rI   )r   r   r$   r:   r   s        r   r"   zAgingCache._buildf   s,    gii3		DO ;<<r   )r   rF   )r1   r2   r3   r<   r   r   r"   __classcell__)rJ   s   @r   rE   rE   X   se         % % % % % %        r   rE   c                       e Zd Zd Zd ZdS )rN   c                 "    || _         || _        d S r   )r#   r)   )r   r#   expirationtimes      r   r   zAgingEntry.__init__l   s    
$r   c                 4    t                      }|| j        k    S r   )r7   r)   )r   ts     r   rL   zAgingEntry.isexpiredp   s    IIDKr   N)r1   r2   r3   r   rL   r(   r   r   rN   rN   k   s2        % % %         r   rN   N)	r<   r   r7   objectr   r5   r8   rE   rN   r(   r   r   <module>rV      s   	 	 !          +6 +6 +6 +6 +6 +6 +6 +6Z5 5 5 5 5: 5 5 5(    F          &                   r   