Implemented ConceptManager with concept creation, modification and deletion
This commit is contained in:
Vendored
+33
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user