def cached_request(self, request):
cache_url = self.cache_url(request.url)<EOL>logger.debug('<STR_LIT>', cache_url)<EOL>cc = self.parse_cache_control(request.headers)<EOL>if "<STR_LIT>" in cc:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>return False<EOL><DEDENT>if "<STR_LIT>" in cc and cc["<STR_LIT>"] == <NUM_LIT:0>:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>return False<EOL><DEDENT>cache_data = self.cache.get(cache_url)<EOL>if cache_data is None:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>return False<EOL><DEDENT>resp = self.serializer.loads(request, cache_data)<EOL>if not resp:<EOL><INDENT>logger.warning("<STR_LIT>")<EOL>return False<EOL><DEDENT>if resp.status == <NUM_LIT>:<EOL><INDENT>msg = (<EOL>'<STR_LIT>'<EOL>"<STR_LIT>"<EOL>)<EOL>logger.debug(msg)<EOL>return resp<EOL><DEDENT>headers = CaseInsensitiveDict(resp.headers)<EOL>if not headers or "<STR_LIT:date>" not in headers:<EOL><INDENT>if "<STR_LIT>" not in headers:<EOL><INDENT>logger.debug("<STR_LIT>")<EOL>self.cache.delete(cache_url)<EOL><DEDENT>logger.debug("<STR_LIT>")<EOL>return False<EOL><DEDENT>now = time.time()<EOL>date = calendar.timegm(parsedate_tz(headers["<STR_LIT:date>"]))<EOL>current_age = max(<NUM_LIT:0>, now - date)<EOL>logger.debug("<STR_LIT>", current_age)<EOL>resp_cc = self.parse_cache_control(headers)<EOL>freshness_lifetime = <NUM_LIT:0><EOL>if "<STR_LIT>" in resp_cc:<EOL><INDENT>freshness_lifetime = resp_cc["<STR_LIT>"]<EOL>logger.debug("<STR_LIT>", freshness_lifetime)<EOL><DEDENT>elif "<STR_LIT>" in headers:<EOL><INDENT>expires = parsedate_tz(headers["<STR_LIT>"])<EOL>if expires is not None:<EOL><INDENT>expire_time = calendar.timegm(expires) - date<EOL>freshness_lifetime = max(<NUM_LIT:0>, expire_time)<EOL>logger.debug("<STR_LIT>", freshness_lifetime)<EOL><DEDENT><DEDENT>if "<STR_LIT>" in cc:<EOL><INDENT>freshness_lifetime = cc["<STR_LIT>"]<EOL>logger.debug(<EOL>"<STR_LIT>", freshness_lifetime<EOL>)<EOL><DEDENT>if "<STR_LIT>" in cc:<EOL><INDENT>min_fresh = cc["<STR_LIT>"]<EOL>current_age += min_fresh<EOL>logger.debug("<STR_LIT>", current_age)<EOL><DEDENT>if freshness_lifetime > current_age:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>logger.debug("<STR_LIT>", freshness_lifetime, current_age)<EOL>return resp<EOL><DEDENT>if "<STR_LIT>" not in headers:<EOL><INDENT>logger.debug('<STR_LIT>')<EOL>self.cache.delete(cache_url)<EOL><DEDENT>return False<EOL>
Return a cached response if it exists in the cache, otherwise
return False.