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 name

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

_abc_impl = <_abc_data object>
async clear()[source]

Delete all items from the cache

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 keys()[source]

Get all keys stored in the cache

Return type

Iterable[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 size()[source]

Get the number of items in the cache

Return type

int

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
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>
async read(key)[source]

Read a single item from the cache. Returns None if the item is missing.

async write(key, item)[source]

Write an item to the cache