session

Summary

CacheMixin(*[, cache])

A mixin class for aiohttp.ClientSession that adds caching support

CachedSession(*[, cache])

A drop-in replacement for aiohttp.ClientSession that adds caching support

Module Contents

class CachedSession(*, cache=None, **kwargs)

Bases: aiohttp_client_cache.session.CacheMixin, aiohttp.ClientSession

A drop-in replacement for aiohttp.ClientSession that adds caching support

Parameters
  • cache (Optional[CacheBackend]) – A cache backend object. See aiohttp_client_cache.backends for options. If not provided, an in-memory cache will be used.

  • connector (Optional[aiohttp.BaseConnector]) –

  • loop (Optional[asyncio.events.AbstractEventLoop]) –

  • cookies (Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]]) –

  • headers (Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]]) –

  • skip_auto_headers (Optional[Iterable[str]]) –

  • auth (Optional[aiohttp.BasicAuth]) –

  • json_serialize (Callable[[Any], str]) –

  • request_class (Type[aiohttp.client_reqrep.ClientRequest]) –

  • response_class (Type[aiohttp.ClientResponse]) –

  • ws_response_class (Type[aiohttp.ClientWebSocketResponse]) –

  • version (aiohttp.http_writer.HttpVersion) –

  • cookie_jar (Optional[aiohttp.abc.AbstractCookieJar]) –

  • connector_owner (bool) –

  • raise_for_status (bool) –

  • read_timeout (Union[float, object]) –

  • conn_timeout (Optional[float]) –

  • timeout (Union[object, aiohttp.ClientTimeout]) –

  • auto_decompress (bool) –

  • trust_env (bool) –

  • requote_redirect_url (bool) –

  • trace_configs (Optional[List[aiohttp.TraceConfig]]) –

  • read_bufsize (int) –

async _request(method, str_or_url, **kwargs)

Wrapper around SessionClient._request() that adds caching

Return type

Union[ClientResponse, CachedResponse]

Parameters
  • method (str) –

  • str_or_url (Union[str, yarl.URL]) –

  • params (Optional[Mapping[str, str]]) –

  • data (Any) –

  • json (Any) –

  • cookies (Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]]) –

  • headers (Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]]) –

  • skip_auto_headers (Optional[Iterable[str]]) –

  • auth (Optional[aiohttp.BasicAuth]) –

  • allow_redirects (bool) –

  • max_redirects (int) –

  • compress (Optional[str]) –

  • chunked (Optional[bool]) –

  • expect100 (bool) –

  • raise_for_status (Optional[bool]) –

  • read_until_eof (bool) –

  • proxy (Optional[Union[str, yarl.URL]]) –

  • proxy_auth (Optional[aiohttp.BasicAuth]) –

  • timeout (Union[aiohttp.ClientTimeout, object]) –

  • verify_ssl (Optional[bool]) –

  • fingerprint (Optional[bytes]) –

  • ssl_context (Optional[ssl.SSLContext]) –

  • ssl (Optional[Union[ssl.SSLContext, bool, aiohttp.Fingerprint]]) –

  • proxy_headers (Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]]) –

  • trace_request_ctx (Optional[types.SimpleNamespace]) –

  • read_bufsize (Optional[int]) –

async delete_expired_responses()

Remove all expired responses from the cache

disabled()

Temporarily disable the cache

Example

>>> async with CachedSession() as session:
>>>     await session.get('http://httpbin.org/ip')
>>>     async with session.disabled():
>>>         # Will return a new response, not a cached one
>>>         await session.get('http://httpbin.org/ip')
class CacheMixin(*, cache=None, **kwargs)

A mixin class for aiohttp.ClientSession that adds caching support

Parameters