mongodb#
Summary#
|
|
|
An async interface for caching objects in MongoDB |
|
Same as |
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
cache_name (
str
) – Database nameconnection (
Optional
[AsyncIOMotorClient
]) – Optional client object to use instead of creating a new oneexpire_after (Union[None, int, float, str, datetime.datetime, datetime.timedelta]) – Time after which a cache entry will be expired; see Cache Expiration for possible formats
urls_expire_after (Optional[Dict[str, Union[None, int, float, str, datetime.datetime, datetime.timedelta]]]) – Expiration times to apply for different URL patterns
allowed_codes (Tuple[int, ...]) – Only cache responses with these status codes
allowed_methods (Tuple[str, ...]) – Only cache requests with these HTTP methods
include_headers (bool) – Cache requests with different headers separately
ignored_params (Optional[Iterable[str]]) – Request parameters to be excluded from the cache key
cache_control (bool) – Use Cache-Control response headers
filter_fn (Union[Callable[[Union[
aiohttp.ClientResponse
, aiohttp_client_cache.response.CachedResponse]], bool], Callable[[Union[aiohttp.ClientResponse
, aiohttp_client_cache.response.CachedResponse]], Awaitable[bool]]]) – function that takes aaiohttp.ClientResponse
object and returns a boolean indicating whether or not that response should be cached. Will be applied to both new and previously cached responsessecret_key (Optional[Union[Iterable, str, bytes]]) – Optional secret key used to sign cache items for added security
salt (Union[str, bytes]) – Optional salt used to sign cache items
serializer – Custom serializer that provides
loads
anddumps
methodshost (str) – Server hostname, IP address, Unix domain socket path, or MongoDB URI
port (int) – Server port
document_class (Type) – Default class to use for documents returned from queries on this client
tz_aware (bool) – Return timezone-aware
datetime
objectsconnect (bool) – Immediately connecting to MongoDB in the background. Otherwise connect on the first operation.
directConnection (bool) – if True, forces this client to connect directly to the specified MongoDB host as a standalone. If false, the client connects to the entire replica set of which the given MongoDB host(s) is a part.
kwargs (
Any
) –
- Parameters
cache_name (
str
) –connection (
Optional
[AsyncIOMotorClient
]) –kwargs (
Any
) –expire_after (Union[None, int, float, str, datetime.datetime, datetime.timedelta]) –
urls_expire_after (Optional[Dict[str, Union[None, int, float, str, datetime.datetime, datetime.timedelta]]]) –
include_headers (bool) –
cache_control (bool) –
filter_fn (Union[Callable[[Union[
aiohttp.ClientResponse
, aiohttp_client_cache.response.CachedResponse]], bool], Callable[[Union[aiohttp.ClientResponse
, aiohttp_client_cache.response.CachedResponse]], Awaitable[bool]]]) –host (str) –
port (int) –
document_class (Type) –
tz_aware (bool) –
connect (bool) –
directConnection (bool) –
- 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 nameconnection (
Optional
[AsyncIOMotorClient
]) – MongoDB connection instance to use instead of creating a new onekwargs (
Any
) – Additional keyword args forAsyncIOMotorClient
- _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 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:
aiohttp_client_cache.backends.mongodb.MongoDBCache
Same as
MongoDBCache
, but pickles values before saving- Parameters
db_name (
str
) –collection_name (
str
) –connection (
Optional
[AsyncIOMotorClient
]) –kwargs (
Any
) –
- _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
- async write(key, item)#
Write an item to the cache