/usr/local/lib/python3.9/site-packages/django/core/cache/backends/__pycache__
a Ӱ�h�7 � @ s� d Z ddlZddlZddlmZ ddlmZ ddlmZ G dd� de�Z G dd � d e �ZG d d� de�Z e� ZdZd d� Zdd� ZG dd� d�Zdd� ZdS )zBase Cache class.� N)� sync_to_async)�ImproperlyConfigured)� import_stringc @ s e Zd ZdS )�InvalidCacheBackendErrorN��__name__� __module__�__qualname__� r r �I/usr/local/lib/python3.9/site-packages/django/core/cache/backends/base.pyr s r c @ s e Zd ZdS )�CacheKeyWarningNr r r r r r s r c @ s e Zd ZdS )�InvalidCacheKeyNr r r r r r s r � c C s d||| f S )z� Default function to generate keys. Construct the key used by all other methods. By default, prepend the `key_prefix`. KEY_FUNCTION can be used to specify an alternate function with custom key making behavior. z%s:%s:%sr )�key� key_prefix�versionr r r �default_key_func s r c C s | durt | �r| S t| �S tS )z] Function to decide which key function to use. Default to ``default_key_func``. N)�callabler r )�key_funcr r r �get_key_func* s r c @ s� e Zd Ze� Zdd� Zefdd�ZdOdd�Zdd � Z dPd d�Z edfdd �Zedfdd�ZdQdd�Z dRdd�Zedfdd�Zedfdd�Zedfdd�Zedfdd�ZdSdd�ZdTdd�ZdUd d!�ZdVd"d#�Zedfd$d%�Zedfd&d'�ZdWd(d)�ZdXd*d+�ZdYd-d.�ZdZd/d0�Zd[d1d2�Zd\d3d4�Zd5d6� Zedfd7d8�Z edfd9d:�Z!d]d;d<�Z"d^d=d>�Z#d?d@� Z$dAdB� Z%d_dCdD�Z&d`dEdF�Z'dadGdH�Z(dbdIdJ�Z)dKdL� Z*dMdN� Z+dS )c� BaseCachec C s |� d|� dd��}|d urDzt|�}W n ttfyB d}Y n0 || _|� di �}|� d|� dd��}zt|�| _W n ttfy� d| _Y n0 |� d|� dd ��}zt|�| _W n ttfy� d | _Y n0 |� d d�| _|� dd �| _t |� d��| _ d S )N�timeout�TIMEOUTi, �OPTIONS�max_entriesZMAX_ENTRIES�cull_frequencyZCULL_FREQUENCY� Z KEY_PREFIX� �VERSION� ZKEY_FUNCTION)�get�int� ValueError� TypeError�default_timeoutZ_max_entriesZ_cull_frequencyr r r r )�self�paramsr �optionsr r r r r �__init__; s* zBaseCache.__init__c C s4 |t kr| j}n|dkrd}|du r(dS t�� | S )zj Return the timeout value usable by this backend based upon the provided timeout. r ���N)�DEFAULT_TIMEOUTr$ �time)r% r r r r �get_backend_timeoutU s zBaseCache.get_backend_timeoutNc C s |du r| j }| �|| j|�S )ap Construct the key used by all other methods. By default, use the key_func to generate a key (which, by default, prepends the `key_prefix' and 'version'). A different key function can be provided at the time of cache construction; alternatively, you can subclass the cache backend to provide custom key making behavior. N)r r r �r% r r r r r �make_keya s zBaseCache.make_keyc C s t |�D ]}t�|t� qdS )z� Warn about keys that would not be portable to the memcached backend. This encourages (but does not force) writing backend-portable cache code. N)�memcache_key_warnings�warnings�warnr )r% r �warningr r r �validate_keyn s zBaseCache.validate_keyc C s | j ||d�}| �|� |S )z!Helper to make and validate keys.�r )r. r3 r- r r r �make_and_validate_keyw s zBaseCache.make_and_validate_keyc C s t d��dS )z� Set a value in the cache if the key does not already exist. If timeout is given, use that timeout for the key; otherwise use the default cache timeout. Return True if the value was stored, False otherwise. z4subclasses of BaseCache must provide an add() methodN��NotImplementedError�r% r �valuer r r r r �add} s �z BaseCache.addc � s t | jdd�||||�I d H S �NT)Zthread_sensitive)r r: r8 r r r �aadd� s �zBaseCache.aaddc C s t d��dS )z� Fetch a given key from the cache. If the key does not exist, return default, which itself defaults to None. z3subclasses of BaseCache must provide a get() methodNr6 �r% r �defaultr r r r r � s z BaseCache.getc � s t | jdd�|||�I d H S r; )r r r= r r r �aget� s �zBaseCache.agetc C s t d��dS )z� Set a value in the cache. If timeout is given, use that timeout for the key; otherwise use the default cache timeout. z3subclasses of BaseCache must provide a set() methodNr6 r8 r r r �set� s z BaseCache.setc � s t | jdd�||||�I d H S r; )r r@ r8 r r r �aset� s �zBaseCache.asetc C s t d��dS )z� Update the key's expiry time using timeout. Return True if successful or False if the key does not exist. z5subclasses of BaseCache must provide a touch() methodNr6 �r% r r r r r r �touch� s �zBaseCache.touchc � s t | jdd�|||�I d H S r; )r rC rB r r r �atouch� s �zBaseCache.atouchc C s t d��dS )zh Delete a key from the cache and return whether it succeeded, failing silently. z6subclasses of BaseCache must provide a delete() methodNr6 r- r r r �delete� s �zBaseCache.deletec � s t | jdd�||�I d H S r; )r rE r- r r r �adelete� s zBaseCache.adeletec C s6 i }|D ](}| j || j|d�}|| jur|||<