@@ -40,7 +40,7 @@ def __init__(
40
40
idempotency_key ,
41
41
status : str = "" ,
42
42
expiry_timestamp : Optional [int ] = None ,
43
- response_data : str = "" ,
43
+ response_data : Optional [ str ] = "" ,
44
44
payload_hash : Optional [str ] = None ,
45
45
) -> None :
46
46
"""
@@ -92,16 +92,16 @@ def status(self) -> str:
92
92
else :
93
93
raise IdempotencyInvalidStatusError (self ._status )
94
94
95
- def response_json_as_dict (self ) -> dict :
95
+ def response_json_as_dict (self ) -> Optional [ dict ] :
96
96
"""
97
97
Get response data deserialized to python dict
98
98
99
99
Returns
100
100
-------
101
- dict
101
+ Optional[ dict]
102
102
previous response data deserialized
103
103
"""
104
- return json .loads (self .response_data )
104
+ return json .loads (self .response_data ) if self . response_data else None
105
105
106
106
107
107
class BasePersistenceLayer (ABC ):
@@ -121,7 +121,6 @@ def __init__(self):
121
121
self .raise_on_no_idempotency_key = False
122
122
self .expires_after_seconds : int = 60 * 60 # 1 hour default
123
123
self .use_local_cache = False
124
- self ._cache : Optional [LRUDict ] = None
125
124
self .hash_function = None
126
125
127
126
def configure (self , config : IdempotencyConfig , function_name : Optional [str ] = None ) -> None :
@@ -279,14 +278,14 @@ def _save_to_cache(self, data_record: DataRecord):
279
278
-------
280
279
281
280
"""
282
- if not self .use_local_cache or self . _cache is None :
281
+ if not self .use_local_cache :
283
282
return
284
283
if data_record .status == STATUS_CONSTANTS ["INPROGRESS" ]:
285
284
return
286
285
self ._cache [data_record .idempotency_key ] = data_record
287
286
288
287
def _retrieve_from_cache (self , idempotency_key : str ):
289
- if not self .use_local_cache or self . _cache is None :
288
+ if not self .use_local_cache :
290
289
return
291
290
cached_record = self ._cache .get (key = idempotency_key )
292
291
if cached_record :
@@ -296,7 +295,7 @@ def _retrieve_from_cache(self, idempotency_key: str):
296
295
self ._delete_from_cache (idempotency_key = idempotency_key )
297
296
298
297
def _delete_from_cache (self , idempotency_key : str ):
299
- if not self .use_local_cache or self . _cache is None :
298
+ if not self .use_local_cache :
300
299
return
301
300
if idempotency_key in self ._cache :
302
301
del self ._cache [idempotency_key ]
0 commit comments