mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
initializes cache in the constructor of the DataServiceCache
This commit is contained in:
parent
0385e5732e
commit
53ce51991f
@ -13,13 +13,10 @@ class DataServiceCache:
|
|||||||
def __init__(self, service: "DataService") -> None:
|
def __init__(self, service: "DataService") -> None:
|
||||||
self._cache: dict[str, Any] = {}
|
self._cache: dict[str, Any] = {}
|
||||||
self.service = service
|
self.service = service
|
||||||
self._cache_initialized = False
|
self._initialize_cache()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cache(self) -> dict[str, Any]:
|
def cache(self) -> dict[str, Any]:
|
||||||
"""Property to lazily initialize the cache."""
|
|
||||||
if not self._cache_initialized:
|
|
||||||
self._initialize_cache()
|
|
||||||
return self._cache
|
return self._cache
|
||||||
|
|
||||||
def _initialize_cache(self) -> None:
|
def _initialize_cache(self) -> None:
|
||||||
@ -27,7 +24,6 @@ class DataServiceCache:
|
|||||||
logger.debug("Initializing cache.")
|
logger.debug("Initializing cache.")
|
||||||
self._cache = self.service.serialize()
|
self._cache = self.service.serialize()
|
||||||
self.service._callback_manager.add_notification_callback(self.update_cache)
|
self.service._callback_manager.add_notification_callback(self.update_cache)
|
||||||
self._cache_initialized = True
|
|
||||||
|
|
||||||
def update_cache(self, parent_path: str, name: str, value: Any) -> None:
|
def update_cache(self, parent_path: str, name: str, value: Any) -> None:
|
||||||
# Remove the part before the first "." in the parent_path
|
# Remove the part before the first "." in the parent_path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user