Skip to content

Add Config singleton cache (scoped first cut of #8)#70

Open
ff225 wants to merge 1 commit into
mainfrom
fix/sciot-008-config-singleton
Open

Add Config singleton cache (scoped first cut of #8)#70
ff225 wants to merge 1 commit into
mainfrom
fix/sciot-008-config-singleton

Conversation

@ff225

@ff225 ff225 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Partial fix for #8 — scoped to avoid conflicting with the in-flight PRs that touch request_handler.py, http_server.py, and message_data.py.

Investigated the current state first: src/sciot/config.py already has solid YAML loading, env-var overrides, and full schema validation — the "prerequisite for modularity" work the issue's own comment worried about is largely done. The real gap was just caching/access: every call site independently called load_server_config/load_client_config and re-parsed + re-validated the YAML on every call, except request_handler.py's own ad-hoc _settings_cache.

Added src/common/config.py::Config, a small singleton-style cache with Config.get_server(path=None) / Config.get_client(path=None) wrapping the existing sciot.config loaders, caching per resolved path. Migrated three call sites that don't touch the in-flight-PR files:

  • src/server/edge/edge_initialization.py (load_delay_config, __main__ block)
  • src/server/logger/log.py (configure_logger_from_settings)
  • src/server/edge/run_edge.py (main)

Scope notes

Left untouched on purpose:

A follow-up can migrate request_handler.py/http_client.py to Config once the in-flight PRs land, and/or fold sciot.config's standalone functions behind Config entirely if that's the desired end state — leaving that as a separate, smaller PR rather than bundling it here.

Test plan

  • Added tests/unit/test_common_config.py: per-path caching (single parse across repeated calls), force_reload, reset(), independent caching across different paths, default-path resolution for both server and client configs.
  • uv run pytest tests/unit/test_common_config.py -q — 8 passed
  • Fast CI suite (tests/unit, integration subset, mqtt, offloading_algo) — 211 passed, 1 skipped, no regressions
  • uv run ruff check on all changed files — clean

Related: closed #3 separately (stale — the "redundant JSON parsing for offloading history" it described was already fixed by existing class-level caches in offloading_algo.py/request_handler.py).

Config loading was scattered: several call sites (edge_initialization.py,
log.py, run_edge.py) re-read and re-validated settings.yaml on every call
instead of caching, unlike request_handler.py's ad-hoc _settings_cache.
Config.get_server()/get_client() wrap the existing sciot.config loaders
with a per-path cache, giving a single access point without touching the
in-flight request_handler.py/http_server.py/message_data.py PRs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eliminate file re-read in offloading decision path

1 participant