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__/fifo_cache.cpython-39.pyc
a

�*�^�&�@sDdZddlmZmZddlmZGdd�de�ZGdd�de�ZdS)	z)A simple first-in-first-out (FIFO) cache.�)�absolute_import�division)�dequec@s�eZdZdZd"dd�Zdd�Zdd	�Zd#d
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zd$dd�Z
dd�Zd%dd�Zdd�Zd&dd�Zd d!�ZdS)'�	FIFOCachez<A class which manages a cache of entries, removing old ones.�dNcCsJt�|�||_|dur*|jdd|_nt||j�|_i|_t�|_dS)N��
)�dict�__init__�
_max_cache�_after_cleanup_count�min�_cleanupr�_queue��self�	max_cacheZafter_cleanup_count�r�3/usr/lib/python3/dist-packages/breezy/fifo_cache.pyr
s
�zFIFOCache.__init__cCs|j||dd�dS)z<Add a value to the cache, there will be no cleanup function.N)�cleanup)�add)r�key�valuerrr�__setitem__&szFIFOCache.__setitem__cCs|j�|�|�|�dS�N)r�remove�_remove�rrrrr�__delitem__*szFIFOCache.__delitem__cCsT||vr||=|j�|�t�|||�|dur:||j|<t|�|jkrP|��dS)a}Add a new value to the cache.

        Also, if the entry is ever removed from the queue, call cleanup.
        Passing it the key and value being removed.

        :param key: The key to store it under
        :param value: The object to store
        :param cleanup: None or a function taking (key, value) to indicate
                        'value' should be cleaned up
        N)r�appendr	rr�lenrr)rrrrrrrr/s
z
FIFOCache.addcCs|jS)z(Get the number of entries we will cache.)r�rrrr�
cache_sizeEszFIFOCache.cache_sizecCsHt|�|jkr|��qt|j�t|�krDtdt|j�t|�f��dS)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.
        zLThe length of the queue should always equal the length of the dict. %s != %sN)r r�_remove_oldestr�AssertionErrorr!rrrrIs
�zFIFOCache.cleanupcCs|r|��qdS)zClear out all of the cache.N)r#r!rrr�clearWszFIFOCache.clearcCs0|j�|d�}t�||�}|dur,|||�|S)z:Remove an entry, making sure to call any cleanup function.N)r�popr	)rrr�valrrrr]s

zFIFOCache._removecCs|j��}|�|�dS)zRemove the oldest entry.N)r�popleftrrrrrr#gs
zFIFOCache._remove_oldestcCsD||_|dur|dd|_nt||�|_t|�|jkr@|��dS)aIncrease/decrease the number of cached entries.

        :param max_cache: The maximum number of entries to cache.
        :param after_cleanup_count: After cleanup, we should have at most this
            many entries. This defaults to 80% of max_cache.
        Nrr)rrr
r rrrrr�resizelszFIFOCache.resizecCst|j��dSr)�NotImplementedError�copyr!rrrr+}szFIFOCache.copycCst|j��dSr)r*r&)rr�defaultrrrr&�sz
FIFOCache.popcCst|j��dSr)r*�popitemr!rrrr-�szFIFOCache.popitemcCs||vr||S|||<|S)zsimilar to dict.setdefaultr)rrZ
defaultvalrrr�
setdefault�szFIFOCache.setdefaultcOs�t|�dkrZ|d}t|t�r:|D]}|�|||�q"qv|dD]\}}|�||�qBnt|�dkrvtdt|���|r�|D]}|�|||�q~dS)zSimilar to dict.update()�rz*update expected at most 1 argument, got %dN)r �
isinstancer	r�	TypeError)r�args�kwargs�argrr'rrr�update�s
�zFIFOCache.update)rN)N)N)N)N)�__name__�
__module__�__qualname__�__doc__r
rrrr"rr%rr#r)r+r&r-r.r5rrrrrs 





rc@sFeZdZdZddd�Zddd�Zdd	�Zd
d�Zdd
�Zddd�Z	dS)�
FIFOSizeCachez�An FIFOCache 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 restricts the cache to be cleaned based on the size of the data.
    �NcCsZtj||d�||_|dur.|jdd|_nt||j�|_d|_||_|durVt|_dS)a�Create a new FIFOSizeCache.

        :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 (defaults to 80% of max_size).
        :param compute_size: A function to compute the size of a value. If
            not supplied we default to 'len'.
        )rNrrr)rr
�	_max_size�_after_cleanup_sizer
�_value_size�
_compute_sizer )r�max_size�after_cleanup_sizeZcompute_sizerrrr
�szFIFOSizeCache.__init__cCsx||vr||=|�|�}||jkr&dS|j�|�t�|||�|durR||j|<|j|7_|j|jkrt|�	�dS)a�Add a new value to the cache.

        Also, if the entry is ever removed from the queue, call cleanup.
        Passing it the key and value being removed.

        :param key: The key to store it under
        :param value: The object to store, this value by itself is >=
            after_cleanup_size, then we will not store it at all.
        :param cleanup: None or a function taking (key, value) to indicate
                        'value' sohuld be cleaned up.
        N)
r?r=rrr	rrr>r<r)rrrrZ	value_lenrrrr�s


zFIFOSizeCache.addcCs|jS)z&Get the number of bytes we will cache.)r<r!rrrr"�szFIFOSizeCache.cache_sizecCs|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)r>r=r#r!rrrr�szFIFOSizeCache.cleanupcCs$t�||�}|j|�|�8_|S)z8Remove an entry, making sure to maintain the invariants.)rrr>r?)rrr'rrrr�szFIFOSizeCache._removecCsNt�||�||_|dur*|dd|_nt||�|_|j|jkrJ|��dS)aIncrease/decrease the amount of cached data.

        :param max_size: The maximum number of bytes to cache.
        :param after_cleanup_size: After cleanup, we should have at most this
            many bytes cached. This defaults to 80% of max_size.
        Nrr)rr)r<r=r
r>r)rr@rArrrr)�szFIFOSizeCache.resize)r;NN)N)N)
r6r7r8r9r
rr"rrr)rrrrr:�s�


r:N)	r9Z
__future__rr�collectionsrr	rr:rrrr�<module>s