-
Notifications
You must be signed in to change notification settings - Fork 0
Raise NotFoundError with additional info #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8c1a863
20ab717
631183a
424813d
b15e7e1
8b4b326
341dfe7
54271de
9c8f848
403ad71
229e401
ec9e93d
d0dd7a9
34b80fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,11 @@ | |
| from starlette.requests import Request | ||
| from starlette.responses import Response | ||
|
|
||
| from fast_cache_middleware.exceptions import StorageError | ||
| from fast_cache_middleware.exceptions import ( | ||
| NotFoundStorageError, | ||
| StorageError, | ||
| TTLExpiredStorageError, | ||
| ) | ||
| from fast_cache_middleware.serializers import BaseSerializer, JSONSerializer, Metadata | ||
|
|
||
| from .base_storage import BaseStorage, StoredResponse | ||
|
|
@@ -62,25 +66,23 @@ async def set( | |
| await self._storage.set(full_key, value, ex=ttl) | ||
| logger.info("Data written to Redis") | ||
|
|
||
| async def get(self, key: str) -> Optional[StoredResponse]: | ||
| async def get(self, key: str) -> StoredResponse: | ||
| """ | ||
| Get response from Redis. If TTL expired returns None. | ||
| """ | ||
| full_key = self._full_key(key) | ||
|
|
||
| if not await self._storage.exists(full_key): | ||
| raise TTLExpiredStorageError(full_key) | ||
|
|
||
| raw_data = await self._storage.get(full_key) | ||
|
|
||
| if raw_data is None: | ||
| logger.debug("Key %s will be removed from Redis - TTL expired", full_key) | ||
| return None | ||
| raise NotFoundStorageError(key) | ||
|
|
||
| logger.debug(f"Takin data from Redis: %s", raw_data) | ||
| try: | ||
| return self._serializer.loads(raw_data) | ||
| except Exception as e: | ||
| logger.warning( | ||
| "Failed to deserialize cached response for key %s: %s", key, e | ||
| ) | ||
| return None | ||
|
|
||
| return self._serializer.loads(raw_data) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Redis Storage Fails on Deserialization ErrorsThe Locations (1) |
||
|
|
||
| async def delete(self, path: re.Pattern) -> None: | ||
| """ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сюда добавил проверку на существование ключа, аналогично тому, что сделано в in_memory решении. Если это избыточно и хватит простой проверки на наличие данных, которая ниже ( 80 строчка ), то уберу.