From 3b59b3d743d04a2cc5ff2d55c9bb8410036682fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Andr=C3=A9s=20Marino=20Rojas?= <47573394+Marinovsky@users.noreply.github.com> Date: Thu, 5 Sep 2024 12:17:21 -0500 Subject: [PATCH] first draft of the solution (#497) --- lean/components/api/auth0_client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lean/components/api/auth0_client.py b/lean/components/api/auth0_client.py index ec9d0046..f1350c1f 100644 --- a/lean/components/api/auth0_client.py +++ b/lean/components/api/auth0_client.py @@ -27,6 +27,7 @@ def __init__(self, api_client: 'APIClient') -> None: :param api_client: the APIClient instance to use when making requests """ self._api = api_client + self._cache = {} def read(self, brokerage_id: str) -> QCAuth0Authorization: """Reads the authorization data for a brokerage. @@ -35,12 +36,18 @@ def read(self, brokerage_id: str) -> QCAuth0Authorization: :return: the authorization data for the specified brokerage """ try: + # First check cache + if brokerage_id in self._cache.keys(): + return self._cache[brokerage_id] payload = { "brokerage": brokerage_id } data = self._api.post("live/auth0/read", payload) - return QCAuth0Authorization(**data) + # Store in cache + result = QCAuth0Authorization(**data) + self._cache[brokerage_id] = result + return result except RequestFailedError as e: return QCAuth0Authorization(authorization=None)