Skip to content

Commit

Permalink
Refactor cache value retrieval in Cache class to handle unpickling er…
Browse files Browse the repository at this point in the history
…ror exception
  • Loading branch information
saleh-mir committed Mar 4, 2024
1 parent cb2259c commit dc9a9ca
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions jesse/services/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def get_value(self, key: str) -> Any:
item['expire_at'] = time() + item['expire_seconds']
self._update_db()

with open(item['path'], 'rb') as f:
try:
try:
with open(item['path'], 'rb') as f:
cache_value = pickle.load(f)
except EOFError:
# File got broken
cache_value = False
return cache_value
except (EOFError, pickle.UnpicklingError):
cache_value = False

return cache_value

def _update_db(self) -> None:
# store/update database
Expand Down

0 comments on commit dc9a9ca

Please sign in to comment.