File: //opt/imunify360/venv/lib/python3.11/site-packages/diskcache/__pycache__/fanout.cpython-311.pyc
�
�'ޜf�� � � d Z ddlZddlZddlZddlZddlmZ ddl
Z
ddlZddlZddl
mZmZmZmZmZ ddlmZmZ G d� d� � Zej e_ dS )z2Fanout cache automatically shards keys and values.� N� )�DEFAULT_SETTINGS�ENOVAL�Cache�Disk�Timeout)�Deque�Indexc �d � e Zd ZdZdddefd�Zed� � � Zd� Ze j
d2d �� � Zd3d�Zd� Z
d4d
�Zd3d�Zd5d�Zd5d�Z d6d�Zd� Zd� Zd� Z d7d�Zd8d�Zd� Zd9d�Zd8d�Zd� Zd� Zd8d�Zd8d�Zd8d �Zd:d"�Z d;d#�Z!d$� Z"d%� Z#d&� Z$d'� Z%d(� Z&d)� Z'd*� Z(d+� Z)d,� Z*e+fd-�Z,d<d/�Z-d=d0�Z.d1� Z/dS )>�FanoutCachez"Cache that shards keys and values.N� g{�G�z�?c �� ������ ��t j d�� � �t �� � �t j �� � �t j �� � �t d }�� d|� � |z �|| _ �| _ �| _
t �����fd�t |� � D � � � � | _
| j
d j j | _ i | _ i | _ i | _ dS )a6 Initialize cache instance.
:param str directory: cache directory
:param int shards: number of shards to distribute writes
:param float timeout: SQLite connection timeout
:param disk: `Disk` instance for serialization
:param settings: any of `DEFAULT_SETTINGS`
Nz
diskcache-)�prefix�
size_limitc 3 �f �K � | ]+}t dt j �d |z � � ���d����V � �,dS )z%03d)� directory�timeout�diskr N� )r �op�join)�.0�numr r �settingsr r s ������p/builddir/build/BUILD/imunify360-venv-2.6.1/opt/imunify360/venv/lib/python3.11/site-packages/diskcache/fanout.py� <genexpr>z'FanoutCache.__init__.<locals>.<genexpr>+ ss �� � � �
�
� �
�
��'�)�V�c�\�:�:���%�
�
�
�
�
�
�
�
�
�
�
� r )�tempfile�mkdtemp�strr �
expanduser�
expandvarsr �pop�_count�
_directory�_disk�tuple�range�_shardsr �hash�_hash�_caches�_deques�_indexes)�selfr �shardsr r r �default_size_limitr s ` ``` @r �__init__zFanoutCache.__init__ s ������ � �� �(��=�=�=�I�� �N�N� ��M�)�,�,� ��M�)�,�,� �-�l�;���\�\�,�0B�C�C�f�L�
����#�����
��
�
�
�
�
�
�
�
� �V�}�}�
�
�
�
�
��� �\�!�_�)�.��
���������
�
�
r c � � | j S )zCache directory.)r% �r/ s r r zFanoutCache.directory: s � � ��r c � � ddh}|t v p||v }|sJ d� |� � � � �t | j d |� � S )Nr r zcannot access {} in cache shardr )r �format�getattrr) )r/ �name�
safe_names�
valid_names r �__getattr__zFanoutCache.__getattr__? sY � ���(�
��-�-�C���1C�
��I�I�<�C�C�D�I�I�I�I�z��t�|�A���-�-�-r Tc # �� K � |s
J d� � �t j � � 5 }| j D ]-}|� d�� � }|� |� � �.dV � ddd� � dS # 1 swxY w Y dS )a� Context manager to perform a transaction by locking the cache.
While the cache is locked, no other write operation is permitted.
Transactions should therefore be as short as possible. Read and write
operations performed in a transaction are atomic. Read operations may
occur concurrent to a transaction.
Transactions may be nested and may not be shared between threads.
Blocks until transactions are held on all cache shards by retrying as
necessary.
>>> cache = FanoutCache()
>>> with cache.transact(): # Atomically increment two keys.
... _ = cache.incr('total', 123.4)
... _ = cache.incr('count', 1)
>>> with cache.transact(): # Atomically calculate average.
... average = cache['total'] / cache['count']
>>> average
123.4
:return: context manager for use in `with` statement
z!retry must be True in FanoutCacheT��retryN)�cl� ExitStackr) �transact�
enter_context)r/ r>