Load a cached response, or return None if it's not available.
(self, request: PreparedRequest)
| 141 | return retval |
| 142 | |
| 143 | def _load_from_cache(self, request: PreparedRequest) -> HTTPResponse | None: |
| 144 | """ |
| 145 | Load a cached response, or return None if it's not available. |
| 146 | """ |
| 147 | # We do not support caching of partial content: so if the request contains a |
| 148 | # Range header then we don't want to load anything from the cache. |
| 149 | if "Range" in request.headers: |
| 150 | return None |
| 151 | |
| 152 | cache_url = request.url |
| 153 | assert cache_url is not None |
| 154 | cache_data = self.cache.get(cache_url) |
| 155 | if cache_data is None: |
| 156 | logger.debug("No cache entry available") |
| 157 | return None |
| 158 | |
| 159 | if isinstance(self.cache, SeparateBodyBaseCache): |
| 160 | body_file = self.cache.get_body(cache_url) |
| 161 | else: |
| 162 | body_file = None |
| 163 | |
| 164 | result = self.serializer.loads(request, cache_data, body_file) |
| 165 | if result is None: |
| 166 | logger.warning("Cache entry deserialization failed, entry ignored") |
| 167 | return result |
| 168 | |
| 169 | def cached_request(self, request: PreparedRequest) -> HTTPResponse | Literal[False]: |
| 170 | """ |
no test coverage detected