Format: application/x-python-code
1 o
2
3 2'h@! � @ sD d dl Z d dlZd dlmZ d dlmZ dZdZG dd� de�Z dS )� N)� BaseCache)�DynamoDbSerializerZ
4 created_at�responsec
5 s\ e Zd ZdZe� Z d(deje de d eje d
6 eje deje dej
7 f� fd
8 d�
9 Zdej
10 fdd�Zd)dedeje
11 dej
12 fdd�Zdedej
13 fdd�Zdedefdd�Z d*dedej
14 deje deje dej
15 f
16 dd�Zd)dedej
17 deje dej
18 fd d!�Zd)dedej
19 deje dej
20 fd"d#�Zdedefd$d%�Zdefd&d'�Z� ZS )+�
21 DynamoDbCachea(
22 Implementation of cachelib.BaseCache that uses an AWS DynamoDb table
23 as the backend.
24
25 Your server process will require dynamodb:GetItem and dynamodb:PutItem
26 IAM permissions on the cache table.
27
28 Limitations: DynamoDB table items are limited to 400 KB in size. Since
29 this class stores cached items in a table, the max size of a cache entry
30 will be slightly less than 400 KB, since the cache key and expiration
31 time fields are also part of the item.
32
33 :param table_name: The name of the DynamoDB table to use
34 :param default_timeout: Set the timeout in seconds after which cache entries
35 expire
36 :param key_field: The name of the hash_key attribute in the DynamoDb
37 table. This must be a string attribute.
38 :param expiration_time_field: The name of the table attribute to store the
39 expiration time in. This will be an int
40 attribute. The timestamp will be stored as
41 seconds past the epoch. If you configure
42 this as the TTL field, then DynamoDB will
43 automatically delete expired entries.
44 :param key_prefix: A prefix that should be added to all keys.
45
46 �python-cache�, � cache_key�expiration_timeN�
47 table_name�default_timeout� key_field�expiration_time_field�
48 key_prefix�kwargsc
49 s t � �|� zdd l}W n ty } ztd�|�d }~ww || _|| _|| _|p*d| _|j di |��| _
50 |jjj
51 | _z| j
52 �|�| _| j�� W d S ty� | j
53 j|dd�g||dd�gd d
54 �} | �� |jdi |��}
55 |
56 j|d|d�d
57 � | j
58 �|�| _| j�� Y d S w )Nr zno boto3 module found� �dynamodb�S)�
59 AttributeNameZ
60 AttributeType�HASH)r ZKeyTypeZPAY_PER_REQUEST)ZAttributeDefinitions� TableNameZ KeySchemaZBillingModeT)ZEnabledr )r ZTimeToLiveSpecification)r )�super�__init__�boto3�ImportError�RuntimeError�_table_name�
61 _key_field�_expiration_time_fieldr �resource�_dynamor Z
62 conditionsZAttr�_attr�Table�_table�load� ExceptionZcreate_tableZwait_until_exists�clientZupdate_time_to_live)�selfr
63 r r r
64 r r r �err�tableZdynamo�� __class__� �GC:\Users\shubh\Videos\agent\nova\Lib\site-packages\cachelib/dynamodb.pyr ) sH
65 ��
66 ���
67 ���zDynamoDbCache.__init__�returnc C s t j �� jt jjd�S )z<Return a tz-aware UTC datetime representing the current time)�tzinfo)�datetime�utcnow�replace�timezone�utc)r&