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.client.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.

async _request(method, str_or_url, expire_after=None, **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.helpers.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.helpers.BasicAuth]) –

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

  • verify_ssl (Optional[bool]) –

  • fingerprint (Optional[bytes]) –

  • ssl_context (Optional[ssl.SSLContext]) –

  • ssl (Optional[Union[ssl.SSLContext, bool, aiohttp.client_reqrep.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