MCPcopy Create free account
hub / github.com/psf/cachecontrol / _load_from_cache

Method _load_from_cache

cachecontrol/controller.py:143–167  ·  view source on GitHub ↗

Load a cached response, or return None if it's not available.

(self, request: PreparedRequest)

Source from the content-addressed store, hash-verified

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 """

Callers 3

cached_requestMethod · 0.95
conditional_headersMethod · 0.95

Calls 4

getMethod · 0.45
get_bodyMethod · 0.45
loadsMethod · 0.45
warningMethod · 0.45

Tested by

no test coverage detected