1
0

Allow setting of cache behaviour
All checks were successful
Python Package / Package (push) Has been skipped

This commit is contained in:
Jon Michael Aanes 2024-03-30 13:26:35 +01:00
parent cef3835a19
commit d426d0b9f6
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -48,6 +48,7 @@ def initialize_session() -> requests.Session:
expire_after=datetime.timedelta(days=1),
stale_if_error=True,
cache_control=False,
urls_expire_after = {},
)
else:
session = requests.Session()
@ -57,7 +58,10 @@ def initialize_session() -> requests.Session:
def setup_limiter(
session: requests.Session, url_prefix: str, **limiter_args
session: requests.Session,
url_prefix: str,
expire_after: datetime.datetime | None = None,
**limiter_args
) -> requests.Session:
"""
Initializes limiter on session for the given domain with the given
@ -67,4 +71,6 @@ def setup_limiter(
"""
if requests_ratelimiter:
session.mount(url_prefix, requests_ratelimiter.LimiterAdapter(**limiter_args))
if requests_cache and expire_after:
session.settings.urls_expire_after[url_prefix] = expire_after
return session