Added first version of DebugManager. Implemented draft of the rule engine
This commit is contained in:
Vendored
+29
-6
@@ -2,7 +2,7 @@ from dataclasses import dataclass, field
|
||||
from threading import RLock
|
||||
from typing import Callable
|
||||
|
||||
from cache.Cache import Cache
|
||||
from cache.BaseCache import BaseCache
|
||||
from core.concept import Concept
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class MultipleEntryError(Exception):
|
||||
|
||||
@dataclass
|
||||
class CacheDefinition:
|
||||
cache: Cache
|
||||
cache: BaseCache
|
||||
use_ref: bool
|
||||
get_key: Callable[[Concept], str] = field(repr=False)
|
||||
persist: bool = True
|
||||
@@ -137,6 +137,15 @@ class CacheManager:
|
||||
with self._lock:
|
||||
return self.caches[cache_name].cache.get(key)
|
||||
|
||||
def get_cache(self, cache_name):
|
||||
"""
|
||||
Return the BaseCache object
|
||||
:param cache_name:
|
||||
:return:
|
||||
"""
|
||||
with self._lock:
|
||||
return self.caches[cache_name].cache
|
||||
|
||||
def copy(self, cache_name):
|
||||
"""
|
||||
get a copy the content of the whole cache as a dictionary
|
||||
@@ -170,6 +179,17 @@ class CacheManager:
|
||||
self.caches[cache_name].cache.delete(key, value)
|
||||
self.is_dirty = True
|
||||
|
||||
def populate(self, cache_name, populate_function, get_key_function):
|
||||
"""
|
||||
Populate a specific cache with a bunch of items
|
||||
:param cache_name:
|
||||
:param populate_function: how to get the items
|
||||
:param get_key_function: how to get the key, out of an item
|
||||
:return:
|
||||
"""
|
||||
with self._lock:
|
||||
self.caches[cache_name].cache.init(populate_function, get_key_function)
|
||||
|
||||
def has(self, cache_name, key):
|
||||
"""
|
||||
True if the value is in cache only. Never try to look in a remote repository
|
||||
@@ -210,7 +230,7 @@ class CacheManager:
|
||||
for values in items.values():
|
||||
update_full_serialisation(values, value)
|
||||
elif isinstance(items, Concept):
|
||||
items.metadata.full_serialization = value
|
||||
items.get_metadata().full_serialization = value
|
||||
|
||||
if self.cache_only:
|
||||
return
|
||||
@@ -245,6 +265,10 @@ class CacheManager:
|
||||
cache_def.cache.clear()
|
||||
|
||||
def dump(self):
|
||||
"""
|
||||
For test purpose, dumps the whole content of the cache manager
|
||||
:return:
|
||||
"""
|
||||
with self._lock:
|
||||
res = {}
|
||||
for cache_name, cache_def in self.caches.items():
|
||||
@@ -252,11 +276,11 @@ class CacheManager:
|
||||
|
||||
return res
|
||||
|
||||
def init_from(self, dump):
|
||||
def init_from_dump(self, dump):
|
||||
with self._lock:
|
||||
for cache_name, content in dump.items():
|
||||
if cache_name in self.caches:
|
||||
self.caches[cache_name].cache.init_from(content)
|
||||
self.caches[cache_name].cache.init_from_dump(content)
|
||||
|
||||
return self
|
||||
|
||||
@@ -267,4 +291,3 @@ class CacheManager:
|
||||
self.caches.clear()
|
||||
self.concept_caches.clear()
|
||||
self.is_dirty = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user