mongodb#

Summary#

MongoDBBackend([cache_name, connection])

Async cache backend for MongoDB (requires motor)

MongoDBCache(db_name, collection_name[, ...])

An async interface for caching objects in MongoDB

MongoDBPickleCache(db_name, collection_name)

Same as MongoDBCache, but pickles values before saving

Module Contents#

class MongoDBBackend(cache_name='aiohttp-cache', connection=None, **kwargs)#

Bases: aiohttp_client_cache.backends.base.CacheBackend

Async cache backend for MongoDB (requires motor)

__init__(cache_name='aiohttp-cache', connection=None, **kwargs)#
Parameters
Parameters
class MongoDBCache(db_name, collection_name, connection=None, **kwargs)#

Bases: aiohttp_client_cache.backends.base.BaseCache

An async interface for caching objects in MongoDB

Parameters
  • db_name (str) – database name (be careful with production databases)

  • collection_name (str) – collection name

  • connection (Optional[AsyncIOMotorClient]) – MongoDB connection instance to use instead of creating a new one

  • kwargs (Any) – Additional keyword args for AsyncIOMotorClient

_abc_impl = <_abc_data object>#
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 contains(key)#

Check if a key is stored in the cache

Parameters

key (str) –

Return type

bool

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

AsyncIterable[str]

async read(key)#

Read an item from the cache. Returns None if the item is missing.

Parameters

key (str) –

Return type

Union[CachedResponse, bytes, str, None]

async size()#

Get the number of items in the cache

Return type

int

async values()#

Get all values stored in the cache

Return type

AsyncIterable[Union[CachedResponse, bytes, str, None]]

async write(key, item)#

Write an item to the cache

Parameters
class MongoDBPickleCache(db_name, collection_name, connection=None, **kwargs)#

Bases: aiohttp_client_cache.backends.mongodb.MongoDBCache

Same as MongoDBCache, but pickles values before saving

Parameters
_abc_impl = <_abc_data object>#
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

AsyncIterable[Union[CachedResponse, bytes, str, None]]

async write(key, item)#

Write an item to the cache