aiohttp_client_cache.backends.mongo module¶
-
class
aiohttp_client_cache.backends.mongo.
MongoDBBackend
(cache_name='aiohttp-cache', connection=None, **kwargs)[source]¶ Bases:
aiohttp_client_cache.backends.base.CacheBackend
MongoDB cache backend
- Parameters
connection (
Optional
[AsyncIOMotorClient
]) – Optional client object to use instead of creating a new one
See
CacheBackend
for additional args.
-
class
aiohttp_client_cache.backends.mongo.
MongoDBCache
(db_name, collection_name, connection=None)[source]¶ Bases:
aiohttp_client_cache.backends.base.BaseCache
An async-compatible interface for caching objects in MongoDB
- Parameters
db_name – database name (be careful with production databases)
collection_name (
str
) – collection nameconnection (
Optional
[AsyncIOMotorClient
]) – MongoDB connection instance to use instead of creating a new one
-
_abc_impl
= <_abc_data object>¶
-
async
contains
(key)[source]¶ Check if a key is stored in the cache
- Return type
bool
- Parameters
key (str) –
-
async
delete
(key)[source]¶ Delete a single item from the cache. Does not raise an error if the item is missing.
- Parameters
key (str) –
-
async
read
(key)[source]¶ Read a single item from the cache. Returns
None
if the item is missing.- Return type
Union
[CachedResponse
,None
,bytes
,str
]- Parameters
key (str) –
-
async
values
()[source]¶ Get all values stored in the cache
- Return type
Iterable
[Union
[CachedResponse
,None
,bytes
,str
]]
-
async
write
(key, item)[source]¶ Write an item to the cache
- Parameters
key (str) –
item (Union[aiohttp_client_cache.response.CachedResponse, None, bytes, str]) –
-
class
aiohttp_client_cache.backends.mongo.
MongoDBPickleCache
(db_name, collection_name, connection=None)[source]¶ Bases:
aiohttp_client_cache.backends.mongo.MongoDBCache
Same as
MongoDBCache
, but pickles values before saving-
_abc_impl
= <_abc_data object>¶
-