Allow setting of cache behaviour
All checks were successful
Python Package / Package (push) Has been skipped
All checks were successful
Python Package / Package (push) Has been skipped
This commit is contained in:
parent
cef3835a19
commit
d426d0b9f6
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user