mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-03-16 21:30:23 +00:00
Do not throw exception on externally invalidated cache keys (#169)
Closes #120
This commit is contained in:
parent
d0b5213014
commit
ac814e5cd4
2 changed files with 20 additions and 11 deletions
|
|
@ -1,6 +1,11 @@
|
|||
What’s new in django-cachalot?
|
||||
==============================
|
||||
|
||||
2.3.4
|
||||
-----
|
||||
|
||||
- Fix bug with externally invalidated cache keys (#120)
|
||||
|
||||
2.3.3
|
||||
-----
|
||||
|
||||
|
|
|
|||
|
|
@ -34,20 +34,24 @@ def _unset_raw_connection(original):
|
|||
|
||||
def _get_result_or_execute_query(execute_query_func, cache,
|
||||
cache_key, table_cache_keys):
|
||||
data = cache.get_many(table_cache_keys + [cache_key])
|
||||
try:
|
||||
data = cache.get_many(table_cache_keys + [cache_key])
|
||||
except KeyError:
|
||||
data = None
|
||||
|
||||
new_table_cache_keys = set(table_cache_keys)
|
||||
new_table_cache_keys.difference_update(data)
|
||||
if data:
|
||||
new_table_cache_keys.difference_update(data)
|
||||
|
||||
if not new_table_cache_keys:
|
||||
try:
|
||||
timestamp, result = data.pop(cache_key)
|
||||
if timestamp >= max(data.values()):
|
||||
return result
|
||||
except (KeyError, TypeError, ValueError):
|
||||
# In case `cache_key` is not in `data` or contains bad data,
|
||||
# we simply run the query and cache again the results.
|
||||
pass
|
||||
if not new_table_cache_keys:
|
||||
try:
|
||||
timestamp, result = data.pop(cache_key)
|
||||
if timestamp >= max(data.values()):
|
||||
return result
|
||||
except (KeyError, TypeError, ValueError):
|
||||
# In case `cache_key` is not in `data` or contains bad data,
|
||||
# we simply run the query and cache again the results.
|
||||
pass
|
||||
|
||||
result = execute_query_func()
|
||||
if result.__class__ not in ITERABLES and isinstance(result, Iterable):
|
||||
|
|
|
|||
Loading…
Reference in a new issue