@@ -783,6 +783,8 @@ def cached_async_http_client(*, provider: str | None = None, timeout: int = 600,
783
783
The client is cached based on the provider parameter. If provider is None, it's used for non-provider specific
784
784
requests (like downloading images). Multiple agents and calls can share the same client when they use the same provider.
785
785
786
+ Each client will get its own transport with its own connection pool. The default pool size is defined by `httpx.DEFAULT_LIMITS`.
787
+
786
788
There are good reasons why in production you should use a `httpx.AsyncClient` as an async context manager as
787
789
described in [encode/httpx#2026](https://github.com/encode/httpx/pull/2026), but when experimenting or showing
788
790
examples, it's very useful not to.
@@ -793,6 +795,8 @@ def cached_async_http_client(*, provider: str | None = None, timeout: int = 600,
793
795
client = _cached_async_http_client (provider = provider , timeout = timeout , connect = connect )
794
796
if client .is_closed :
795
797
# This happens if the context manager is used, so we need to create a new client.
798
+ # Since there is no API from `functools.cache` to clear the cache for a specific
799
+ # key, clear the entire cache here as a workaround.
796
800
_cached_async_http_client .cache_clear ()
797
801
client = _cached_async_http_client (provider = provider , timeout = timeout , connect = connect )
798
802
return client
@@ -801,17 +805,11 @@ def cached_async_http_client(*, provider: str | None = None, timeout: int = 600,
801
805
@cache
802
806
def _cached_async_http_client (provider : str | None , timeout : int = 600 , connect : int = 5 ) -> httpx .AsyncClient :
803
807
return httpx .AsyncClient (
804
- transport = _cached_async_http_transport (),
805
808
timeout = httpx .Timeout (timeout = timeout , connect = connect ),
806
809
headers = {'User-Agent' : get_user_agent ()},
807
810
)
808
811
809
812
810
- @cache
811
- def _cached_async_http_transport () -> httpx .AsyncHTTPTransport :
812
- return httpx .AsyncHTTPTransport ()
813
-
814
-
815
813
DataT = TypeVar ('DataT' , str , bytes )
816
814
817
815
0 commit comments