mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-07 05:50:41 +02:00
updates data service cache (methods to set and get values)
This commit is contained in:
parent
114a1c6fdc
commit
3497962fca
@ -1,7 +1,12 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from pydase.utils.serializer import set_nested_value_by_path
|
from pydase.utils.serializer import (
|
||||||
|
SerializationPathError,
|
||||||
|
SerializationValueError,
|
||||||
|
get_nested_dict_by_path,
|
||||||
|
set_nested_value_by_path,
|
||||||
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from pydase import DataService
|
from pydase import DataService
|
||||||
@ -24,11 +29,11 @@ class DataServiceCache:
|
|||||||
logger.debug("Initializing cache.")
|
logger.debug("Initializing cache.")
|
||||||
self._cache = self.service.serialize()
|
self._cache = self.service.serialize()
|
||||||
|
|
||||||
def update_cache(self, parent_path: str, name: str, value: Any) -> None:
|
def update_cache(self, full_access_path: str, value: Any) -> None:
|
||||||
# Remove the part before the first "." in the parent_path
|
set_nested_value_by_path(self._cache, full_access_path, value)
|
||||||
parent_path = ".".join(parent_path.split(".")[1:])
|
|
||||||
|
|
||||||
# Construct the full path
|
def get_value_dict_from_cache(self, full_access_path: str) -> dict[str, Any] | None:
|
||||||
full_path = f"{parent_path}.{name}" if parent_path else name
|
try:
|
||||||
|
return get_nested_dict_by_path(self._cache, full_access_path)
|
||||||
set_nested_value_by_path(self._cache, full_path, value)
|
except (SerializationPathError, SerializationValueError, KeyError):
|
||||||
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user