Format: application/x-python-code
1 o
2
3 2'h^
4 � @ s@ d dl Zd dlmZ d dlmZ d dlmZ G dd� de�ZdS )� N)�time)� BaseCache)�SimpleSerializerc
5 @ s e Zd ZdZe� Z d$dedefdd�Zdefd d
6 �Z de
7 ddfd
8 d�Zd%dd�Zd%dd�Z
9 deje defdd�Zdedejfdd�Z d&dedejdeje deje fdd�Zd&dedejdeje defdd�Zdedefdd�Zdedefd d!�Zdefd"d#�ZdS )'�SimpleCachea� Simple memory cache for single process environments. This class exists
10 mainly for the development server and is not 100% thread safe. It tries
11 to use as many atomic operations as possible and no locks for simplicity
12 but it could happen under heavy load that keys are added multiple times.
13
14 :param threshold: the maximum number of items the cache stores before
15 it starts deleting some.
16 :param default_timeout: the default timeout that is used if no timeout is
17 specified on :meth:`~BaseCache.set`. A timeout of
18 0 indicates that the cache never expires.
19 �� �, � threshold�default_timeoutc C s t �| |� i | _|pd| _d S )Nr )r �__init__�_cache�
20 _threshold)�selfr r � r �EC:\Users\shubh\Videos\agent\nova\Lib\site-packages\cachelib/simple.pyr
21 s zSimpleCache.__init__�returnc C s t | j�| jkS �N)�lenr r �r
22 r r r �_over_threshold s zSimpleCache._over_threshold�nowNc s4 � fdd�| j �� D �}|D ] }| j �|d � qd S )Nc s g | ]\}\}}|� k r|�qS r r )�.0�k�expires�_�r r r �
23 <listcomp>$ s z/SimpleCache._remove_expired.<locals>.<listcomp>)r �items�pop)r
24 r Ztoremover r r r �_remove_expired# s �zSimpleCache._remove_expiredc C sJ dd� t | j�� dd� d�D �}|D ]}| j�|d � | �� s" d S qd S )Nc s s � | ]\}}|V qd S r r )r r �vr r r � <genexpr>) s �
25 �z,SimpleCache._remove_older.<locals>.<genexpr>c S s | d d S )N� r r )�itemr r r �<lambda>* s z+SimpleCache._remove_older.<locals>.<lambda>)�key)�sortedr r r r )r
26 Z k_orderedr r r r �
27 _remove_older( s ���zSimpleCache._remove_olderc C s0 | � � rt� }| �|� | � � r| �� d S d S r )r r r r&