Make sure the cache is ensured before manipulating it

This commit is contained in:
Oskar Hahn 2019-02-04 17:26:32 +01:00
parent a6043ba8d5
commit fae270a1d6

View File

@ -133,6 +133,11 @@ class ElementCache:
Returns the new generated change_id.
"""
if not self.ensured:
raise RuntimeError(
"Call element_cache.ensure_cache before changing elements."
)
deleted_elements = []
changed_elements = []
for element_id, data in elements.items():
@ -265,6 +270,11 @@ class ElementCache:
# If the restricted_data_cache is not used, there is nothing to do
return
if not self.ensured:
raise RuntimeError(
"Call element_cache.ensure_cache before updating restricted data."
)
# Try to write a special key.
# If this succeeds, there is noone else currently updating the cache.
# TODO: Make a timeout. Else this could block forever