1414# limitations under the License.
1515"""Handling session initialization for httpx"""
1616
17- from contextlib import asynccontextmanager , contextmanager
18- from functools import cached_property
17+ from contextlib import asynccontextmanager
1918from typing import Union
2019
2120import hishel
3332from ghga_connector .constants import TIMEOUT
3433
3534
36- class HttpxClientConfigurator :
35+ class RetryHandler :
3736 """Helper class to make max_retries user configurable"""
3837
39- @cached_property
40- def retry_handler ( self ):
38+ @classmethod
39+ def basic ( cls ):
4140 """Configure client retry handler with exponential backoff"""
4241 return AsyncRetrying (
4342 reraise = True ,
@@ -58,22 +57,6 @@ def retry_handler(self):
5857 )
5958
6059
61- retry_handler = HttpxClientConfigurator ().retry_handler
62-
63-
64- @contextmanager
65- def httpx_client ():
66- """Yields a context manager httpx client and closes it afterward"""
67- with httpx .Client (
68- timeout = TIMEOUT ,
69- limits = httpx .Limits (
70- max_connections = CONFIG .max_concurrent_downloads ,
71- max_keepalive_connections = CONFIG .max_concurrent_downloads ,
72- ),
73- ) as client :
74- yield client
75-
76-
7760def get_cache_transport (
7861 wrapped_transport : Union [httpx .AsyncBaseTransport , None ] = None ,
7962) -> hishel .AsyncCacheTransport :
@@ -84,7 +67,8 @@ def get_cache_transport(
8467 """
8568 cache_transport = hishel .AsyncCacheTransport (
8669 transport = wrapped_transport or httpx .AsyncHTTPTransport (),
87- storage = hishel .AsyncInMemoryStorage (ttl = 1800 ), # persist for 30 minutes
70+ # set ttl to expected lifetime of presigned URL - min-fresh
71+ storage = hishel .AsyncInMemoryStorage (ttl = 57 , capacity = 512 ),
8872 controller = hishel .Controller (
8973 cacheable_methods = ["POST" , "GET" ],
9074 cacheable_status_codes = [200 , 201 ],
0 commit comments