Skip to content

Commit c32be3c

Browse files
author
anthonyp97
committed
add logging and handle none values
1 parent 1da2963 commit c32be3c

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

cache_helper/decorators.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,25 @@ def wrapper(*args, **kwargs):
3636
)
3737
value = sentinel
3838

39-
if value is sentinel:
39+
if value is None:
40+
logger.warning(
41+
'None cache value found for cache key: {}, function cache key: {}, value: {}'.format(
42+
cache_key, function_cache_key, value
43+
)
44+
)
45+
46+
# Need to check for None as well because the cache client sends a None response at times
47+
if value is sentinel or value is None:
4048
value = func(*args, **kwargs)
4149
# Try and set the key, value pair in the cache.
4250
# But if it fails on an error from the underlying
4351
# cache system, handle it.
4452
try:
53+
logger.info(
54+
'Setting cache key: {}, value: {} for function cache key: {}'.format(
55+
cache_key, value, function_cache_key
56+
)
57+
)
4558
cache.set(cache_key, value, timeout)
4659
except CacheSetError:
4760
logger.warning(
@@ -91,12 +104,25 @@ def wrapper(*args, **kwargs):
91104
)
92105
value = sentinel
93106

94-
if value is sentinel:
107+
if value is None:
108+
logger.warning(
109+
'None cache value found for cache key: {}, function cache key: {}, value: {}'.format(
110+
cache_key, function_cache_key, value
111+
)
112+
)
113+
114+
# Need to check for None as well because the cache client sends a None response at times
115+
if value is sentinel or value is None:
95116
value = func(*args, **kwargs)
96117
# Try and set the key, value pair in the cache.
97118
# But if it fails on an error from the underlying
98119
# cache system, handle it.
99120
try:
121+
logger.info(
122+
'Setting cache key: {}, value: {} for function cache key: {}'.format(
123+
cache_key, value, function_cache_key
124+
)
125+
)
100126
cache.set(cache_key, value, timeout)
101127
except CacheSetError:
102128
logger.warning(
@@ -167,12 +193,25 @@ def __call__(self, *args, **kwargs):
167193
)
168194
value = sentinel
169195

170-
if value is sentinel:
196+
if value is None:
197+
logger.warning(
198+
'None cache value found for cache key: {}, function cache key: {}, value: {}'.format(
199+
cache_key, function_cache_key, value
200+
)
201+
)
202+
203+
# Need to check for None as well because the cache client sends a None response at times
204+
if value is sentinel or value is None:
171205
value = self.func(*args, **kwargs)
172206
# Try and set the key, value pair in the cache.
173207
# But if it fails on an error from the underlying
174208
# cache system, handle it.
175209
try:
210+
logger.info(
211+
'Setting cache key: {}, value: {} for function cache key: {}'.format(
212+
cache_key, value, function_cache_key
213+
)
214+
)
176215
cache.set(cache_key, value, timeout)
177216
except CacheSetError:
178217
logger.warning(

0 commit comments

Comments
 (0)