Skip to content

Commit

Permalink
Use InMemoryCache
Browse files Browse the repository at this point in the history
  • Loading branch information
karpetrosyan committed Dec 12, 2023
1 parent 5bed811 commit 21a1aa3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions githubkit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Config:
user_agent: str
follow_redirects: bool
timeout: httpx.Timeout
http_cache: bool

def dict(self) -> Dict[str, Any]:
return asdict(self)
Expand Down Expand Up @@ -65,11 +66,13 @@ def get_config(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
) -> Config:
return Config(
build_base_url(base_url),
build_accept(accept_format, previews),
build_user_agent(user_agent),
follow_redirects,
build_timeout(timeout),
http_cache,
)
9 changes: 7 additions & 2 deletions githubkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
):
...

Expand All @@ -95,6 +96,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
):
...

Expand All @@ -110,6 +112,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
):
...

Expand All @@ -124,6 +127,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
):
auth = auth or UnauthAuthStrategy() # type: ignore
self.auth: A = ( # type: ignore
Expand All @@ -140,6 +144,7 @@ def __init__(
self.__async_client: ContextVar[Optional[httpx.AsyncClient]] = ContextVar(
"async_client", default=None
)
self._http_cache = http_cache

# sync context
def __enter__(self):
Expand Down Expand Up @@ -190,7 +195,7 @@ def _get_client_defaults(self):
def _create_sync_client(self) -> httpx.Client:
return httpx.Client(
**self._get_client_defaults(),
transport=hishel.CacheTransport(httpx.HTTPTransport()),
transport=hishel.CacheTransport(httpx.HTTPTransport(), storage=hishel.InMemoryStorage()),
)

# get or create sync client
Expand All @@ -209,7 +214,7 @@ def get_sync_client(self) -> Generator[httpx.Client, None, None]:
def _create_async_client(self) -> httpx.AsyncClient:
return httpx.AsyncClient(
**self._get_client_defaults(),
transport=hishel.AsyncCacheTransport(httpx.AsyncHTTPTransport()),
transport=hishel.AsyncCacheTransport(httpx.AsyncHTTPTransport(), storage=hishel.AsyncInMemoryStorage()),
)

# get or create async client
Expand Down
3 changes: 3 additions & 0 deletions githubkit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
):
...

Expand All @@ -99,6 +100,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
):
...

Expand All @@ -114,6 +116,7 @@ def __init__(
user_agent: Optional[str] = None,
follow_redirects: bool = True,
timeout: Optional[Union[float, httpx.Timeout]] = None,
http_cache: bool = True,
):
...

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include = ["githubkit/py.typed"]
python = "^3.8"
pydantic = ">=2.0.0, <3.0.0, !=2.5.0, !=2.5.1"
httpx = ">=0.23.0, <1.0.0"
hishel = ">=0.0.19"
hishel = ">=0.0.20"
typing-extensions = "^4.3.0"
anyio = { version = "^3.6.1", optional = true }
PyJWT = { version = "^2.4.0", extras = ["crypto"], optional = true }
Expand Down

0 comments on commit 21a1aa3

Please sign in to comment.