DynamoDB#
DynamoDB cache backend. For usage details, see Backends: DynamoDB.
DynamoDB cache backend. |
|
A dictionary-like interface for DynamoDB table |
- class requests_cache.backends.dynamodb.DynamoDbCache(table_name='http_cache', *, ttl=True, connection=None, decode_content=True, serializer=None, **kwargs)[source]#
Bases:
BaseCache
DynamoDB cache backend. By default, responses are only partially serialized into a DynamoDB-compatible document format.
- Parameters:
table_name (
str
) – DynamoDB table nameconnection (
Optional
[ServiceResource
]) – DynamoDB Resource object to use instead of creating a new onettl (
bool
) – Use DynamoDB TTL to automatically remove expired itemskwargs – Additional keyword arguments for
resource()
decode_content (
bool
) –serializer (
Union
[str
,SerializerPipeline
,Stage
,None
]) –
- clear()#
Delete all items from the cache
- close()#
Close any open backend connections
- contains(key=None, request=None, url=None)#
Check if the specified request is cached
- Parameters:
request (
Union
[Request
,PreparedRequest
,CachedRequest
,None
]) – Check for a matching request, according to current request matching settingsurl (
Optional
[str
]) – Check for a matching GET request with the specified URL
- create_key(request, match_headers=None, **kwargs)#
Create a normalized cache key from a request object
- Parameters:
request (
Union
[Request
,PreparedRequest
,CachedRequest
]) –
- Return type:
- delete(*keys, expired=False, invalid=False, older_than=None, requests=None, urls=None)#
Remove responses from the cache according one or more conditions.
- Parameters:
keys (
str
) – Remove responses with these cache keysexpired (
bool
) – Remove all expired responsesinvalid (
bool
) – Remove all invalid responses (that can’t be deserialized with current settings)older_than (
Union
[None
,int
,float
,str
,datetime
,timedelta
]) – Remove responses older than this value, relative toresponse.created_at
requests (
Optional
[Iterable
[Union
[Request
,PreparedRequest
,CachedRequest
]]]) – Remove matching responses, according to current request matching settingsurls (
Optional
[Iterable
[str
]]) – Remove matching GET requests for the specified URL(s)
- filter(valid=True, expired=True, invalid=False, older_than=None)#
Get responses from the cache, with optional filters for which responses to include:
- Parameters:
valid (
bool
) – Include valid and unexpired responses; set toFalse
to get only expired/invalid/old responsesexpired (
bool
) – Include expired responsesinvalid (
bool
) – Include invalid responses (as an emptyCachedResponse
)older_than (
Union
[None
,int
,float
,str
,datetime
,timedelta
]) – Get responses older than this value, relative toresponse.created_at
- Return type:
- get_response(key, default=None)#
Retrieve a response from the cache, if it exists
- Parameters:
key (
str
) – Cache key for the responsedefault – Value to return if key is not in the cache
- Return type:
- recreate_keys()#
Recreate cache keys for all previously cached responses
- remove_expired_responses(expire_after=None)#
- reset_expiration(expire_after=None)#
Set a new expiration value to set on existing cache items
- save_response(response, cache_key=None, expires=None)#
Save a response to the cache
- class requests_cache.backends.dynamodb.DynamoDbDict(table_name, ttl=True, connection=None, serializer=<requests_cache.serializers.pipeline.SerializerPipeline object>, **kwargs)[source]#
Bases:
BaseStorage
A dictionary-like interface for DynamoDB table
- Parameters:
table_name (
str
) – DynamoDB table nameconnection (
Optional
[ServiceResource
]) – DynamoDB Resource object to use instead of creating a new onettl (
bool
) – Use DynamoDB TTL to automatically remove expired itemskwargs – Additional keyword arguments for
resource()
serializer (
Union
[str
,SerializerPipeline
,Stage
,None
]) –
- bulk_delete(keys)[source]#
Delete multiple keys from the cache. Does not raise errors for missing keys.
- close()#
Close any open backend connections
- deserialize(key, value)[source]#
Handle Binary objects from a custom serializer
- Parameters:
value (
TypeVar
(VT
)) –
- get(k[, d]) D[k] if k in D, else d. d defaults to None. #
- items() a set-like object providing a view on D's items #
- keys() a set-like object providing a view on D's keys #
- pop(k[, d]) v, remove specified key and return the corresponding value. #
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair #
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D #
- update([E, ]**F) None. Update D from mapping/iterable E and F. #
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v