From e7b97d23b7bffa39f45ba08db2f3921b88c8d8da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 11 Feb 2020 17:03:25 +0100 Subject: [PATCH] fix: Better handling of cache issues --- lookyloo/lookyloo.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 7f54fb3..8fd3e72 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -85,12 +85,16 @@ class Lookyloo(): self.redis.hmset(str(report_dir), cache) self.redis.hset('lookup_dirs', uuid, str(report_dir)) - def report_cache(self, report_dir: Union[str, Path]) -> Dict: + def report_cache(self, report_dir: Union[str, Path]) -> Optional[Dict[str, Union[str, int]]]: if isinstance(report_dir, Path): report_dir = str(report_dir) cached = self.redis.hgetall(report_dir) - cached['redirects'] = json.loads(cached['redirects']) - return cached + if all(key in ['uuid', 'title', 'timestamp', 'url', 'redirects'] for key in cached): + cached['redirects'] = json.loads(cached['redirects']) + return cached + + self.logger.warning(f'Cache ({report_dir}) is invalid: {json.dumps(report_dir, indent=2)}') + return None def _init_existing_dumps(self) -> None: for report_dir in self.report_dirs: