From 12f45d7df7f568bb52079c38423d927e10b09ec5 Mon Sep 17 00:00:00 2001 From: Jules Dejaeghere Date: Sun, 16 Jun 2024 15:18:31 +0200 Subject: [PATCH] Add params to class and docstring --- src/open_irceline/api.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/open_irceline/api.py b/src/open_irceline/api.py index 32eba4b..b536039 100644 --- a/src/open_irceline/api.py +++ b/src/open_irceline/api.py @@ -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: