Skip to content

Commit

Permalink
Use sensible caching defaults by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dseomn committed Oct 25, 2023
1 parent 605af6e commit 2eac5f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
13 changes: 9 additions & 4 deletions rock_paper_sand/justwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ def _response_is_ok(response: requests.Response) -> bool:
def requests_session() -> Generator[requests.Session, None, None]:
"""Returns a context manager for a session for the JustWatch API."""
with requests_cache.CachedSession(
**network.requests_cache_defaults(),
expire_after=datetime.timedelta(hours=20),
allowable_methods=("GET", "HEAD", "POST"),
filter_fn=_response_is_ok,
**(
network.requests_cache_defaults()
| dict[str, Any](
expire_after=datetime.timedelta(hours=20),
cache_control=False,
allowable_methods=("GET", "HEAD", "POST"),
filter_fn=_response_is_ok,
)
),
) as session:
network.configure_session(session, additional_retry_methods=("POST",))
yield session
Expand Down
3 changes: 3 additions & 0 deletions rock_paper_sand/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Utilities for accessing network resources."""

from collections.abc import Collection, Mapping
import datetime
import importlib.metadata
import os.path
from typing import Any
Expand Down Expand Up @@ -46,6 +47,8 @@ def requests_cache_defaults() -> Mapping[str, Any]:
),
serializer="json",
),
expire_after=datetime.timedelta(minutes=5),
cache_control=True,
)


Expand Down
1 change: 0 additions & 1 deletion rock_paper_sand/wikidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def requests_session() -> Generator[requests.Session, None, None]:
"""Returns a context manager for a session for Wikidata APIs."""
with requests_cache.CachedSession(
**network.requests_cache_defaults(),
cache_control=True,
) as session:
network.configure_session(session)
yield session
Expand Down

0 comments on commit 2eac5f0

Please sign in to comment.