File: //home/arjun/projects/env/lib64/python3.10/site-packages/cachelib/__pycache__/file.cpython-310.pyc
o
!wez- � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z
d dlmZ d dl
mZ d dlmZ d dlmZ d dlmZ d dlmZ G d d
� d
e�ZdS )� N)�contextmanager)�md5)�Path)�sleep)�time)� BaseCache)�FileSystemSerializerc @ s� e Zd ZdZdZdZe� Zdddefde de
d e
d
eje
dej
f
dd
�Zde
fdd�Zede
fdd��Z dAdeje
deje
ddfdd�Zdeje
de
fdd�Zde defdd�Zdeje ddf fdd�Zdefdd �Zd!eddfd"d#�Zdefd$d%�ZdBd&d'�Zdefd(d)�Zd*e de fd+d,�Zd*e dej
fd-d.�ZdCd*e dej
deje
defd/d0�Z 1dDd*e dej
deje
d2edef
d3d4�Z!dEd*e d2edefd5d6�Z"d*e defd7d8�Z#d9ej$d:ej
d;ej
dej
fd<d=�Z%e&d>e d
e dejfd?d@��Z'dS )F�FileSystemCachea� A cache that stores the items on the file system. This cache depends
on being the only user of the `cache_dir`. Make absolutely sure that
nobody but this cache stores files there or otherwise the cache will
randomly delete files therein.
:param cache_dir: the directory where cache files are stored.
:param threshold: the maximum number of items the cache stores before
it starts deleting some. A threshold value of 0
indicates no threshold.
:param default_timeout: the default timeout that is used if no timeout is
specified on :meth:`~BaseCache.set`. A timeout of
0 indicates that the cache never expires.
:param mode: the file mode wanted for the cache files, default 0600
:param hash_method: Default hashlib.md5. The hash method used to
generate the filename for cached results.
z.__wz_cache�__wz_cache_counti� i, N� cache_dir� threshold�default_timeout�mode�hash_methodc
C s� t �| |� || _|| _|| _|| _| jd u r| �� | _zt�| j� W n t y= } z
|j
t
jkr3� W Y d }~nd }~ww | jdkrQ| jt
t| �� ��d� d S d S )Nr ��value)r �__init__�_path�
_threshold�_hash_method�_mode�_get_compatible_platform_mode�os�makedirs�OSError�errno�EEXIST�
_update_count�len�list� _list_dir)�selfr r r
r r �ex� r# �F/home/arjun/projects/env/lib/python3.10/site-packages/cachelib/file.pyr , s$
���
�zFileSystemCache.__init__�returnc C s d}t �� dkrtj}|S )Ni� �Windows)�platform�system�stat�S_IWRITE)r! r r# r# r$ r K s z-FileSystemCache._get_compatible_platform_modec C s | � | j�pdS �Nr )�get�_fs_count_file�r! r# r# r$ �_file_countQ s zFileSystemCache._file_count�deltar c C s<