mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-05 05:00:40 +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
|
||||
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:
|
||||
from pydase import DataService
|
||||
@ -24,11 +29,11 @@ class DataServiceCache:
|
||||
logger.debug("Initializing cache.")
|
||||
self._cache = self.service.serialize()
|
||||
|
||||
def update_cache(self, parent_path: str, name: str, value: Any) -> None:
|
||||
# Remove the part before the first "." in the parent_path
|
||||
parent_path = ".".join(parent_path.split(".")[1:])
|
||||
def update_cache(self, full_access_path: str, value: Any) -> None:
|
||||
set_nested_value_by_path(self._cache, full_access_path, value)
|
||||
|
||||
# Construct the full path
|
||||
full_path = f"{parent_path}.{name}" if parent_path else name
|
||||
|
||||
set_nested_value_by_path(self._cache, full_path, value)
|
||||
def get_value_dict_from_cache(self, full_access_path: str) -> dict[str, Any] | None:
|
||||
try:
|
||||
return get_nested_dict_by_path(self._cache, full_access_path)
|
||||
except (SerializationPathError, SerializationValueError, KeyError):
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user