mongodb¶
Summary¶
|
|
|
An async interface for caching objects in MongoDB |
|
Same as |
Module Contents¶
- class MongoDBBackend(cache_name='aiohttp-cache', connection=None, **kwargs)¶
Bases:
CacheBackend
Async cache backend for MongoDB
Notes
Requires motor
Accepts keyword arguments for
pymongo.MongoClient
- Parameters:
cache_name (
str
) – Database nameconnection (
AsyncIOMotorClient
) – Optional client object to use instead of creating a new onekwargs (
Any
) – Additional keyword arguments forCacheBackend
or backend connection
- class MongoDBCache(db_name, collection_name, connection=None, **kwargs)¶
Bases:
BaseCache
An async interface for caching objects in MongoDB
- Parameters:
db_name (
str
) – database name (be careful with production databases)collection_name (
str
) – collection nameconnection (
AsyncIOMotorClient
) – MongoDB connection instance to use instead of creating a new onekwargs (
Any
) – Additional keyword args forAsyncIOMotorClient
- async bulk_delete(keys)¶
Delete item(s) from the cache. Does not raise an error if the item is missing.
- Parameters:
keys (
set
)
- async clear()¶
Delete all items from the cache
- async delete(key)¶
Delete an item from the cache. Does not raise an error if the item is missing.
- Parameters:
key (
str
)
- async keys()¶
Get all keys stored in the cache
- Return type:
- async read(key)¶
Read an item from the cache. Returns
None
if the item is missing.
- async values()¶
Get all values stored in the cache
- Return type:
- class MongoDBPickleCache(db_name, collection_name, connection=None, **kwargs)¶
Bases:
MongoDBCache
Same as
MongoDBCache
, but pickles values before saving- Parameters:
db_name (
str
)collection_name (
str
)connection (
AsyncIOMotorClient
)kwargs (
Any
)
- async read(key)¶
Read an item from the cache. Returns
None
if the item is missing.
- async values()¶
Get all values stored in the cache
- Return type:
- async write(key, item)¶
Write an item to the cache