从缓存中获取response 注意: 属性值为空: -raw : urllib3.response.HTTPResponse -connection:requests.adapters.HTTPAdapter -history 属性含义改变: - request 由requests 改为Request @param: save_cached 当无缓存 直接下载 下载完是
(self, save_cached=True)
| 506 | self._cache_db.strset(self._cached_redis_key, response.to_dict, ex=expire_time) |
| 507 | |
| 508 | def get_response_from_cached(self, save_cached=True): |
| 509 | """ |
| 510 | 从缓存中获取response |
| 511 | 注意: |
| 512 | 属性值为空: |
| 513 | -raw : urllib3.response.HTTPResponse |
| 514 | -connection:requests.adapters.HTTPAdapter |
| 515 | -history |
| 516 | |
| 517 | 属性含义改变: |
| 518 | - request 由requests 改为Request |
| 519 | @param: save_cached 当无缓存 直接下载 下载完是否保存缓存 |
| 520 | @return: |
| 521 | """ |
| 522 | response_dict = self._cache_db.strget(self._cached_redis_key) |
| 523 | if not response_dict: |
| 524 | log.info("无response缓存 重新下载") |
| 525 | response_obj = self.get_response(save_cached=save_cached) |
| 526 | else: |
| 527 | response_dict = eval(response_dict) |
| 528 | response_obj = Response.from_dict(response_dict) |
| 529 | return response_obj |
| 530 | |
| 531 | def del_response_cached(self): |
| 532 | self._cache_db.clear(self._cached_redis_key) |
no test coverage detected