+class _CachingFetcher(Fetcher):
+
+ def __init__(
+ self,
+ session: requests_cache.CachedSession,
+ timeout: int) -> None:
+ self._session = session
+ self._timeout = timeout
+ self._request_count = 0
+ self._cache_hit_count = 0
+
+ def fetch(self, url: str) -> bytes:
+ with self._session.get(url, timeout=self._timeout) as r:
+ r.raise_for_status()
+ self._request_count += 1
+ self._cache_hit_count += int(r.from_cache)
+ return r.content
+
+ @property
+ def request_count(self) -> int:
+ return self._request_count
+
+ @property
+ def cache_hit_count(self) -> int:
+ return self._cache_hit_count
+
+