Skip to main content

utils/
db_cache.rs

1//! Process-wide handle to the app database for read-through caches living in
2//! this crate (lyrics, metadata enrichment). Registered once at startup; every
3//! cache degrades gracefully to fetch-only when unset (tests, early boot).
4
5use std::sync::OnceLock;
6
7static DB: OnceLock<db::Db> = OnceLock::new();
8
9/// Register the database used by the persistent caches. Called once in `main`.
10pub fn init(handle: db::Db) {
11    let _ = DB.set(handle);
12}
13
14/// The registered database, if any. Public so caches in crates above `utils`
15/// (e.g. discord-presence cover art) share the same handle.
16pub fn get() -> Option<&'static db::Db> {
17    DB.get()
18}