Skip to content
Snippets Groups Projects
Commit 7fb4414b authored by Rosen Matev's avatar Rosen Matev :sunny:
Browse files

Merge branch 'rm-tonic-exception' into 'master'

Better exception from PyConf.tonic configurable caching

See merge request !3401
parents 6e3f8e8c c18e7c8f
No related branches found
No related tags found
2 merge requests!3702merge counter decoder into Louis' original branch,!3401Better exception from PyConf.tonic configurable caching
Pipeline #3541699 passed
......@@ -668,6 +668,9 @@ def _configurable_wrapper(wrapped, _, args, kwargs):
except TypeError as e:
log.info("Cannot determine key to cache {}({})\n {}".format(
_print_live_object(wrapped), kwargs, str(e)))
cache_key = None
if cache_key is None:
return wrapped(**kwargs)
try:
......@@ -680,18 +683,21 @@ def _configurable_wrapper(wrapped, _, args, kwargs):
_print_live_object(wrapped), kwargs, result_key,
new_result_key))
log.debug("Cache hit!")
return result
except KeyError:
log.debug("Cache miss!")
result = wrapped(**kwargs)
try:
# obtain an immutable representation of result
result_key = wrapped._serialize(result)
wrapped._cache[cache_key] = (result, result_key)
except TypeError as e:
log.info(
'Cannot serialize return value of {}, not caching\n {}'.
format(_print_live_object(wrapped), str(e)))
wrapped._serialize = None # do not try to cache further calls
pass
result = wrapped(**kwargs)
try:
# obtain an immutable representation of result
result_key = wrapped._serialize(result)
wrapped._cache[cache_key] = (result, result_key)
except TypeError as e:
log.info(
'Cannot serialize return value of {}, not caching\n {}'.format(
_print_live_object(wrapped), str(e)))
wrapped._serialize = None # do not try to cache further calls
return result
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment