Implemented ConceptManager with concept creation, modification and deletion

This commit is contained in:
2020-12-08 15:36:21 +01:00
parent d364878ddb
commit 4b6e1dd55b
40 changed files with 1847 additions and 979 deletions
+33 -2
View File
@@ -6,14 +6,22 @@ from cache.BaseCache import BaseCache
from core.concept import Concept
@dataclass
class MultipleEntryError(Exception):
"""
Exception raised when trying to alter an entry with multiple element
without giving the origin of the element
"""
def __init__(self, key):
self.key = key
key: str
@dataclass
class ConceptNotFound(Exception):
"""
Thrown when you try to remove a concept that is not found
"""
concept: object
@dataclass
@@ -127,6 +135,29 @@ class CacheManager:
# pass
# self.is_dirty = True
def remove_concept(self, concept):
"""
Remove a concept from all caches
:param concept:
:return:
"""
with self._lock:
# the first concept cache must the one where all concept are unique
# eg it has to be the concept by id
ref_cache_def = self.caches[self.concept_caches[0]]
concept_id = ref_cache_def.get_key(concept)
ref_concept = ref_cache_def.cache.get(concept_id)
if ref_concept is None:
raise ConceptNotFound(concept)
for cache_name in self.concept_caches:
cache_def = self.caches[cache_name]
key = cache_def.get_key(ref_concept)
cache_def.cache.delete(key, ref_concept)
self.is_dirty = True
def get(self, cache_name, key):
"""
From concept cache, get an entry