HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/lru_cache.cpython-39.pyc
a

�*�^�-�@sjdZddlmZmZddlmZddlmZmZe	�Z
Gdd�de	�ZGdd	�d	e	�ZGd
d�de�Z
dS)
z)A simple least-recently-used (LRU) cache.�)�absolute_import�division�)�trace)�	viewitems�viewkeysc@s$eZdZdZdZdd�Zdd�ZdS)�_LRUNodez:This maintains the linked-list which is the lru internals.)�prev�next_key�key�valuecCsd|_t|_||_||_dS�N)r	�	_null_keyr
rr)�selfrr�r�2/usr/lib/python3/dist-packages/breezy/lru_cache.py�__init__&sz_LRUNode.__init__cCs0|jdurd}n|jj}d|jj|j|j|fS)Nz%s(%r n:%r p:%r))r	r�	__class__�__name__r
)rZprev_keyrrr�__repr__,s
�z_LRUNode.__repr__N)r�
__module__�__qualname__�__doc__�	__slots__rrrrrrr!src@s�eZdZdZd$dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	d%dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd&d d!�Zd'd"d#�ZdS)(�LRUCachez?A class which manages a cache of entries, removing unused ones.�dNcCs"i|_d|_d|_|�||�dSr
)�_cache�_most_recently_used�_least_recently_used�_update_max_cache�r�	max_cache�after_cleanup_countrrrr8szLRUCache.__init__cCs
||jvSr
)r)rrrrr�__contains__@szLRUCache.__contains__cCsr|j}||}|j}||ur"|jS|j}|j}|tur>||_n||}||_||_|j|_||_||_d|_|jSr
)rrrr	r
rrr)rr�cache�nodeZmruZ	node_prevr
�	node_nextrrr�__getitem__Cs"zLRUCache.__getitem__cCs
t|j�Sr
)�lenr�rrrr�__len__bszLRUCache.__len__cCsp|turtd��||jvr6|j|}||_|�|�nt||�}||j|<|�|�t|j�|jkrl|��dS)�Add a new value to the cache�cannot use _null_key as a keyN)	r�
ValueErrorrr�_record_accessrr(�
_max_cache�cleanup)rrrr%rrr�__setitem__es




zLRUCache.__setitem__cCs|jS)z(Get the number of entries we will cache.)r/r)rrr�
cache_sizevszLRUCache.cache_sizecCs*|j�|d�}|dur|S|�|�|jSr
)r�getr.r)rr�defaultr%rrrr3zs

zLRUCache.getcCstt|j��S)aGet the list of keys currently cached.

        Note that values returned here may not be available by the time you
        request them later. This is simply meant as a peak into the current
        state.

        :return: An unordered list of keys that are currently cached.
        )�listrrr)rrr�keys�s
z
LRUCache.keyscCstdd�t|j�D��S)z9Get a new dict with the same key:value pairs as the cachecss|]\}}||jfVqdSr
)r)�.0�k�nrrr�	<genexpr>��z#LRUCache.as_dict.<locals>.<genexpr>)�dictrrr)rrr�as_dict�szLRUCache.as_dictcCst|j�|jkr|��qdS)z�Clear the cache until it shrinks to the requested size.

        This does not completely wipe the cache, just makes sure it is under
        the after_cleanup_count.
        N)r(r�_after_cleanup_count�_remove_lrur)rrrr0�szLRUCache.cleanupcCs�|jdur||_||_dS||jur(dS||jur:|j|_|jdurN|j|j_|jturl|j|j}|j|_|jj|_||j_||_d|_dS)zRecord that key was accessed.N)rrr	r
rrr�rr%r&rrrr.�s"






zLRUCache._record_accesscCsr||jur|j|_|j�|j�|jdur0d|_|jdurD|j|j_|jturb|j|j}|j|_d|_t|_dSr
)rr	r�poprrr
rr@rrr�_remove_node�s




zLRUCache._remove_nodecCs|�|j�dS)z�Remove one entry from the lru, and handle consequences.

        If there are no more references to the lru, then this entry should be
        removed from the cache.
        N)rBrr)rrrr?�szLRUCache._remove_lrucCs|jr|��qdS)zClear out all of the cache.N)rr?r)rrr�clear�szLRUCache.clearcCs|j||d�dS)z1Change the number of entries that will be cached.)r"N)rr rrr�resize�s�zLRUCache.resizecCs:||_|dur |jdd|_nt||j�|_|��dS�N��
)r/r>�minr0r rrrr�s�zLRUCache._update_max_cache)rN)N)N)N)rrrrrr#r'r*r1r2r3r6r=r0r.rBr?rCrDrrrrrr5s"



rc@sFeZdZdZddd�Zdd�Zdd	�Zd
d�Zddd
�Zddd�Z	dS)�LRUSizeCacheaUAn LRUCache that removes things based on the size of the values.

    This differs in that it doesn't care how many actual items there are,
    it just restricts the cache to be cleaned up after so much data is stored.

    The size of items added will be computed using compute_size(value), which
    defaults to len() if not supplied.
    �NcCsHd|_||_|durt|_|j||d�tj|tt|d�d�d�dS)a�Create a new LRUSizeCache.

        :param max_size: The max number of bytes to store before we start
            clearing out entries.
        :param after_cleanup_size: After cleaning up, shrink everything to this
            size.
        :param compute_size: A function to compute the size of the values. We
            use a function here, so that you can pass 'len' if you are just
            using simple strings, or a more complex function if you are using
            something like a list of strings, or even a custom object.
            The function should take the form "compute_size(value) => integer".
            If not supplied, it defaults to 'len()'
        rN��after_cleanup_size�r)r!)�_value_size�
_compute_sizer(�_update_max_sizerr�max�int)r�max_sizerLZcompute_sizerrrr�szLRUSizeCache.__init__cCs�|turtd��|j�|d�}|�|�}||jkr^t�d|||j|j�|durZ|�	|�dS|dur|t
||�}||j|<n|j|�|j�8_|j|7_|�
|�|j|jkr�|��dS)r+r,NzfAdding the key %r to an LRUSizeCache failed. value %d is too big to fit in a the cache with size %d %d)rr-rr3rO�_after_cleanup_sizerZmutter�	_max_sizerBrrNrr.r0)rrrr%Z	value_lenrrrr1s(

�


zLRUSizeCache.__setitem__cCs|j|jkr|��qdS)z�Clear the cache until it shrinks to the requested size.

        This does not completely wipe the cache, just makes sure it is under
        the after_cleanup_size.
        N)rNrTr?r)rrrr0szLRUSizeCache.cleanupcCs&|j|�|j�8_t�||�dSr
)rNrOrrrB)rr%rrrrB)szLRUSizeCache._remove_nodecCs.|j||d�tt|d�d�}|�|�dS)z/Change the number of bytes that will be cached.rKrMrN)rPrQrRr)rrSrLr!rrrrD-szLRUSizeCache.resizecCs2||_|dur |jdd|_nt||j�|_dSrE)rUrTrH)rrSrLrrrrP3szLRUSizeCache._update_max_size)rJNN)N)N)
rrrrrr1r0rBrDrPrrrrrI�s	�


rIN)rZ
__future__rr�rZsixishrr�objectrrrrIrrrr�<module>s.