Add params to class and docstring

This commit is contained in:
Jules 2024-06-16 15:18:31 +02:00
parent c62b135b52
commit 12f45d7df7
Signed by: jdejaegh
GPG key ID: 99D6D184CA66933A

View file

@ -18,9 +18,9 @@ class IrcelineApiError(Exception):
class IrcelineBaseClient:
def __init__(self, session: aiohttp.ClientSession) -> None:
def __init__(self, session: aiohttp.ClientSession, cache_size: int = 20) -> None:
self._session = session
self._cache = SizedDict(20)
self._cache = SizedDict(cache_size)
async def _api_wrapper(self, url: str, querystring: dict = None, headers: dict = None, method: str = 'GET'):
"""
@ -54,6 +54,12 @@ class IrcelineBaseClient:
raise IrcelineApiError(f"Something really wrong happened! {exception}") from exception
async def _api_cached_wrapper(self, url: str, method: str = 'GET'):
"""
Call the API but uses cache based on the ETag value to avoid repeated calls for the same ressource
:param url: url to fetch
:param method: HTTP method (default to GET)
:return: response from the client
"""
if url in self._cache:
headers = {"If-None-Match": f'{self._cache.get(url, {}).get("etag")}'}
else: