Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/py/_path/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/py/_path/__pycache__/cacheutil.cpython-37.pyc

B

���]w
�@sddZddlmZGdd�de�ZGdd�de�ZGdd�de�ZGd	d
�d
e�ZGdd�de�Zd
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@sHeZdZddd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Zdd�Z	dS)�
BasicCache�cCs"||_t||d�|_i|_dS)N�)�
maxentries�int�prunenum�_dict)�selfr�r�C/opt/alt/python37/lib/python3.7/site-packages/py/_path/cacheutil.py�__init__szBasicCache.__init__cCs|j��dS)N)r	�clear)r
rrrrszBasicCache.clearcCs
|j|S)N)r	)r
�keyrrr�	_getentryszBasicCache._getentrycCs|��||j|<dS)N)�_prunelowestweightr	)r
r�entryrrr�	_putentryszBasicCache._putentryFcCs,y|j|=Wntk
r&|r"�YnXdS)N)r	�KeyError)r
r�raisingrrr�delentrys
zBasicCache.delentrycCsBy|�|�}Wn,tk
r:|�||�}|�||�YnX|jS)N)rr�_buildr�value)r
r�builderrrrr�
getorbuild$szBasicCache.getorbuildcCsnt|j�}||jkrjdd�|j��D�}|��||j}|dkrjx&|d|�D]\}}|j|dd�qPWdS)z' prune out entries with lowest weight. cSsg|]\}}|j|f�qSr)�weight)�.0rrrrr�
<listcomp>1sz1BasicCache._prunelowestweight.<locals>.<listcomp>rNF)r)�lenr	r�items�sortrr)r
Z
numentriesr�indexrrrrrr,s


zBasicCache._prunelowestweightN)r)F)
�__name__�
__module__�__qualname__r
rrrrrrrrrrr
s

rc@seZdZdZdd�ZdS)�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.
    cCs t�}|�}t�}t|||�S)N)�gettime�WeightedCountingEntry)r
rr�start�val�endrrrrGszBuildcostAccessCache._buildN)r"r#r$�__doc__rrrrrr%:s
r%c@s$eZdZdd�Zdd�Zee�ZdS)r'cCs||_||_|_dS)N)�_valuer�
_oneweight)r
rZ	oneweightrrrr
OszWeightedCountingEntry.__init__cCs|j|j7_|jS)N)rr-r,)r
rrrrSszWeightedCountingEntry.valueN)r"r#r$r
r�propertyrrrrr'Nsr'cs2eZdZdZd
�fdd�	Zdd�Zdd	�Z�ZS)�
AgingCachez; This cache prunes out cache entries that are too old.
    r�$@cstt|��|�||_dS)N)�superr/r
�
maxseconds)r
rr2)�	__class__rrr
[szAgingCache.__init__cCs(|j|}|��r$|�|�t|��|S)N)r	�	isexpiredrr)r
rrrrrr_s


zAgingCache._getentrycCs|�}t|t�|j�}|S)N)�
AgingEntryr&r2)r
rrr)rrrrrfszAgingCache._build)rr0)r"r#r$r+r
rr�
__classcell__rr)r3rr/Xsr/c@seZdZdd�Zdd�ZdS)r5cCs||_||_dS)N)rr)r
rZexpirationtimerrrr
lszAgingEntry.__init__cCst�}||jkS)N)r&r)r
�trrrr4pszAgingEntry.isexpiredN)r"r#r$r
r4rrrrr5ksr5N)	r+rr&�objectrr%r'r/r5rrrr�<module>
s-