apsbits.utils.stored_dict#
Storage-backed Dictionary#
A dictionary that writes its contents to a YAML file. This mutable mapping automatically
synchronizes its in-memory state to a human-readable YAML file on disk shortly after
updates. It replaces bluesky.utils.PersistentDict
and
ensures that all contents are JSON serializable.
|
Dictionary that synchronizes its contents to a YAML storage file. |
Classes
|
Dictionary that synchronizes its contents to a YAML storage file. |
- class apsbits.utils.stored_dict.StoredDict(file: str | Path, delay: float = 5, title: str | None = None, serializable: bool = True)[source]#
Bases:
MutableMapping
Dictionary that synchronizes its contents to a YAML storage file.
This mutable mapping stores key-value pairs in an internal cache and periodically writes its contents to a YAML file on disk. Changes are flushed after a configurable delay. The YAML serialization and deserialization are handled by the static methods dump and load.
- __init__(file: str | Path, delay: float = 5, title: str | None = None, serializable: bool = True) None [source]#
Initialize the StoredDict instance.
- Parameters:
file (str or pathlib.Path) – Path to the YAML file for storing dictionary
contents.
delay (float) – Time delay in seconds after the last update before
seconds. (synchronizing to storage. Defaults to 5)
title (str, optional) – Comment to include at the top of the YAML file.
provided (If not)
StoredDict.". (defaults to "Written by)
serializable (bool) – If True, ensure that new dictionary entries
serializable. (are JSON)
- Returns:
None
- _abc_impl = <_abc._abc_data object>#
- _delayed_sync_to_storage()[source]#
Sync the metadata to storage. Start a time-delay thread. New writes to the metadata dictionary will extend the deadline. Sync once the deadline is reached.