Skip to main content

Module schema_cache

Module schema_cache 

Source
Expand description

Process-local schema cache — 0.7.2.

The planner / review / executor chain already reads rustio.schema.json on every invocation. What was missing was a runtime-visible reload: the dashboard and suggestion engine baked their decisions against the compiled AdminEntry list, so after rustio schema regenerated the file or after an ai apply, the admin kept showing stale suggestions until the operator restarted the server.

This module gives the admin a single refreshable source of truth: a RwLock<Option<Schema>> behind a OnceLock. The suggestion engine reads from here; the /admin/schema/reload handler writes to here; the apply handler writes to here automatically on success. No restart required.

§Safety

  • The cache stores only a parsed Schema — no handlers, no mutable project state. Reloading a bad file returns Err; the previous good value stays in the cache.
  • Reads take a RwLock read guard. Writes take a write guard and swap the inner Option. A poisoned lock falls back to “cache empty” rather than panic.
  • The cache is pure data — it cannot cause file writes, DB access, or any side effect.

Structs§

CachedSchema

Functions§

format_loaded_at
Formats loaded_at as YYYY-MM-DD HH:MM:SS UTC for the dashboard footer.
refresh
Re-read rustio.schema.json and atomically replace the cached value. Returns the freshly-loaded schema on success; leaves the previous value intact on any error.
refresh_best_effort
Like refresh but does not surface errors. Used by the apply handler to auto-reload after a successful write; the user-visible refresh endpoint returns a clear error on failure.
snapshot
Snapshot of the currently-cached schema, or None if the file is missing / unreadable / unparsable.