Skip to content

Commit

Permalink
cache make_get
Browse files Browse the repository at this point in the history
  • Loading branch information
abyesilyurt committed Jun 25, 2024
1 parent ac9d3c1 commit 258afeb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/syft/src/syft/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

# third party
from argon2 import PasswordHasher
from cachetools import TTLCache
from cachetools import cached
from pydantic import field_validator
import requests
from requests import Response
Expand Down Expand Up @@ -200,6 +202,8 @@ def session(self) -> Session:
return self.session_cache

def _make_get(self, path: str, params: dict | None = None) -> bytes:
if params is None:
return self._make_get_no_params(path)
url = self.url.with_path(path)
response = self.session.get(
str(url),
Expand All @@ -218,6 +222,26 @@ def _make_get(self, path: str, params: dict | None = None) -> bytes:

return response.content

@cached(cache=TTLCache(maxsize=128, ttl=300))
def _make_get_no_params(self, path: str) -> bytes:
print(path)
url = self.url.with_path(path)
response = self.session.get(
str(url),
headers=self.headers,
verify=verify_tls(),
proxies={},
)
if response.status_code != 200:
raise requests.ConnectionError(
f"Failed to fetch {url}. Response returned with code {response.status_code}"
)

# upgrade to tls if available
self.url = upgrade_tls(self.url, response)

return response.content

def _make_post(
self,
path: str,
Expand Down

0 comments on commit 258afeb

Please sign in to comment.