Skip to content

Commit b9f26e3

Browse files
committed
Rename variables for improved consistency.
1 parent 8891126 commit b9f26e3

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

cache_helper/decorators.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def _get_function_cache_keys(func_name: str, func_signature: Signature, args: tu
3030
"""
3131
bound_arguments = func_signature.bind(*args, **kwargs)
3232
bound_arguments.apply_defaults()
33-
function_cache_key = utils.get_function_cache_key(func_name, bound_arguments.args, bound_arguments.kwargs)
34-
hashed_function_cache_key = utils.get_hashed_cache_key(function_cache_key)
35-
return hashed_function_cache_key, function_cache_key
33+
cache_key_string = utils.get_function_cache_key(func_name, bound_arguments.args, bound_arguments.kwargs)
34+
cache_key_hashed = utils.get_hashed_cache_key(cache_key_string)
35+
return cache_key_hashed, cache_key_string
3636

3737

3838
def cached(timeout):
@@ -42,16 +42,16 @@ def _cached(func):
4242

4343
@wraps(func)
4444
def wrapper(*args, **kwargs):
45-
cache_key, function_cache_key = _get_function_cache_keys(func_name, func_signature, args, kwargs)
45+
cache_key_hashed, cache_key_string = _get_function_cache_keys(func_name, func_signature, args, kwargs)
4646

4747
# We need to determine whether the object exists in the cache, and since we may have stored a literal value
4848
# None, use a sentinel object as the default
4949
sentinel = object()
5050
try:
51-
value = cache.get(cache_key, sentinel)
51+
value = cache.get(cache_key_hashed, sentinel)
5252
except Exception:
5353
logger.warning(
54-
f'Error retrieving value from Cache for Key: {function_cache_key}',
54+
f'Error retrieving value from Cache for Key: {cache_key_string}',
5555
exc_info=True,
5656
)
5757
value = sentinel
@@ -61,7 +61,7 @@ def wrapper(*args, **kwargs):
6161
if value is None:
6262
logger.warning(
6363
'None cache value found for cache key: {}, function cache key: {}, value: {}'.format(
64-
cache_key, function_cache_key, value
64+
cache_key_hashed, cache_key_string, value
6565
)
6666
)
6767

@@ -71,10 +71,10 @@ def wrapper(*args, **kwargs):
7171
# But if it fails on an error from the underlying
7272
# cache system, handle it.
7373
try:
74-
cache.set(cache_key, value, timeout)
74+
cache.set(cache_key_hashed, value, timeout)
7575
except CacheSetError:
7676
logger.warning(
77-
f'Error saving value to Cache for Key: {function_cache_key}',
77+
f'Error saving value to Cache for Key: {cache_key_string}',
7878
exc_info=True,
7979
)
8080

@@ -106,17 +106,17 @@ def _cached(func):
106106
def wrapper(*args, **kwargs):
107107
# replace the first arg for caching purposes because it will be the class itself
108108
cls_adjusted_args = (None, *args[1:])
109-
cache_key, function_cache_key = _get_function_cache_keys(
109+
cache_key_hashed, cache_key_string = _get_function_cache_keys(
110110
func_name, func_signature, cls_adjusted_args, kwargs
111111
)
112112
# We need to determine whether the object exists in the cache, and since we may have stored a literal value
113113
# None, use a sentinel object as the default
114114
sentinel = object()
115115
try:
116-
value = cache.get(cache_key, sentinel)
116+
value = cache.get(cache_key_hashed, sentinel)
117117
except Exception:
118118
logger.warning(
119-
f'Error retrieving value from Cache for Key: {function_cache_key}',
119+
f'Error retrieving value from Cache for Key: {cache_key_string}',
120120
exc_info=True,
121121
)
122122
value = sentinel
@@ -126,7 +126,7 @@ def wrapper(*args, **kwargs):
126126
if value is None:
127127
logger.warning(
128128
'None cache value found for cache key: {}, function cache key: {}, value: {}'.format(
129-
cache_key, function_cache_key, value
129+
cache_key_hashed, cache_key_string, value
130130
)
131131
)
132132

@@ -136,10 +136,10 @@ def wrapper(*args, **kwargs):
136136
# But if it fails on an error from the underlying
137137
# cache system, handle it.
138138
try:
139-
cache.set(cache_key, value, timeout)
139+
cache.set(cache_key_hashed, value, timeout)
140140
except CacheSetError:
141141
logger.warning(
142-
f'Error saving value to Cache for Key: {function_cache_key}',
142+
f'Error saving value to Cache for Key: {cache_key_string}',
143143
exc_info=True,
144144
)
145145

@@ -195,16 +195,16 @@ def __get__(self, obj, objtype):
195195
return fn
196196

197197
def __call__(self, *args, **kwargs):
198-
cache_key, function_cache_key = self.create_cache_key(*args, **kwargs)
198+
cache_key_hashed, cache_key_string = self.create_cache_key(*args, **kwargs)
199199

200200
# We need to determine whether the object exists in the cache, and since we may have stored a literal value
201201
# None, use a sentinel object as the default
202202
sentinel = object()
203203
try:
204-
value = cache.get(cache_key, sentinel)
204+
value = cache.get(cache_key_hashed, sentinel)
205205
except Exception:
206206
logger.warning(
207-
f'Error retrieving value from Cache for Key: {function_cache_key}',
207+
f'Error retrieving value from Cache for Key: {cache_key_string}',
208208
exc_info=True,
209209
)
210210
value = sentinel
@@ -214,7 +214,7 @@ def __call__(self, *args, **kwargs):
214214
if value is None:
215215
logger.warning(
216216
'None cache value found for cache key: {}, function cache key: {}, value: {}'.format(
217-
cache_key, function_cache_key, value
217+
cache_key_hashed, cache_key_string, value
218218
)
219219
)
220220

@@ -224,10 +224,10 @@ def __call__(self, *args, **kwargs):
224224
# But if it fails on an error from the underlying
225225
# cache system, handle it.
226226
try:
227-
cache.set(cache_key, value, timeout)
227+
cache.set(cache_key_hashed, value, timeout)
228228
except CacheSetError:
229229
logger.warning(
230-
f'Error saving value to Cache for Key: {function_cache_key}',
230+
f'Error saving value to Cache for Key: {cache_key_string}',
231231
exc_info=True,
232232
)
233233

@@ -241,14 +241,14 @@ def _invalidate(self, *args, **kwargs):
241241
:param kwargs: The kwargs passed into the original function.
242242
:rtype: None
243243
"""
244-
cache_key, _ = self.create_cache_key(*args, **kwargs)
245-
cache.delete(cache_key)
244+
cache_key_hashed, _ = self.create_cache_key(*args, **kwargs)
245+
cache.delete(cache_key_hashed)
246246

247247
def create_cache_key(self, *args, **kwargs):
248248
# Need to include the first arg (self) in the cache key
249249
func_name = utils.get_function_name(self.func)
250250
func_signature = signature(self.func)
251-
cache_key, function_cache_key = _get_function_cache_keys(func_name, func_signature, args, kwargs)
252-
return cache_key, function_cache_key
251+
cache_key_hashed, cache_key_string = _get_function_cache_keys(func_name, func_signature, args, kwargs)
252+
return cache_key_hashed, cache_key_string
253253

254254
return wrapper

0 commit comments

Comments
 (0)