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)