File: //usr/lib/python3/dist-packages/django/core/cache/backends/__pycache__/base.cpython-310.pyc
o
3�aR( � @ s� d Z ddlZddlZddlmZ ddlmZ G dd� de�ZG dd� de�Z G d d
� d
e
�Ze� Z
dZdd
� Zdd� ZG dd� d�Zdd� ZdS )zBase Cache class.� N)�ImproperlyConfigured)�
import_stringc @ � e Zd ZdS )�InvalidCacheBackendErrorN��__name__�
__module__�__qualname__� r
r
�A/usr/lib/python3/dist-packages/django/core/cache/backends/base.pyr � r c @ r )�CacheKeyWarningNr r
r
r
r r
r r
c @ r )�InvalidCacheKeyNr r
r
r
r r r 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�Zd-dd�Zedfdd �Z d.d
d�Z
edfdd
�Zedfdd�Zd-dd�Z
d-dd�Zedfdd�Zd-dd�Zd/dd�Zd/dd�Zdd� Zedfdd �Zd-d!d"�Zd#d$� Zd%d&� Zd/d'd(�Zd/d)d*�Zd+d,� ZdS )0� BaseCachec C s |� d|� dd��}|d ur"zt|�}W n
ttfy! d}Y nw || _|� di �}|� d|� dd��}zt|�| _W n ttfyJ d| _Y nw |� d|� dd ��}zt|�| _W n ttfyj d | _Y nw |� d
d�| _|� dd
�| _t |� d��| _
d S )N�timeout�TIMEOUTi, �OPTIONS�max_entries�MAX_ENTRIES�cull_frequency�CULL_FREQUENCY� �
KEY_PREFIX� �VERSION� �KEY_FUNCTION)�get�int�
ValueError� TypeError�default_timeout�_max_entries�_cull_frequencyr r r r )�self�paramsr �optionsr r r
r
r �__init__9 s0 �
�
�zBaseCache.__init__c C s4 |t kr| j}n|dkrd}|du rdS 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_timeoutS 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_key_ s zBaseCache.make_keyc C � t d��)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() method��NotImplementedError�r, r �valuer r r
r
r �addl s z
BaseCache.addc C r6 )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() methodr7 )r, r �defaultr r
r
r r% v � z
BaseCache.getc C r6 )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() methodr7 r9 r
r
r �set} r= z
BaseCache.setc C r6 )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() methodr7 )r, r r r r
r
r �touch� r= zBaseCache.touchc C r6 )zh
Delete a key from the cache and return whether it succeeded, failing
silently.
z6subclasses of BaseCache must provide a delete() methodr7 r4 r
r
r �delete� r= zBaseCache.deletec C s6 i }|D ]}| j || j|d�}|| jur|||<