Déplacer cache registry dans les crates individuelles (pattern singleton)
Au lieu d'avoir un cache_registry centralisé dans pmoupnp qui créait des dépendances circulaires, chaque crate a maintenant son propre singleton global : - pmoaudiocache : register_audio_cache() + get_audio_cache() - pmocovers : register_cover_cache() + get_cover_cache() Changes: - Add singleton pattern to pmoaudiocache/src/lib.rs - Add singleton pattern to pmocovers/src/lib.rs - Add once_cell dependency to both crates - Update pmoplaylist to use pmoaudiocache::get_audio_cache() as fallback - Update pmoupnp/upnp_server.rs to use register_* functions - Update pmoupnp/lib.rs to reexport only get_* (not register_*) - Remove pmoupnp/src/cache_registry.rs (no longer needed) pmoupnp réexporte get_audio_cache() et get_cover_cache() pour compatibilité avec le code existant (pmosource, etc.).
This commit is contained in:
@@ -21,6 +21,9 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
# Async
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
|
||||
# Singleton
|
||||
once_cell = "1.20"
|
||||
|
||||
# Serveur HTTP (optionnel pour l'extension)
|
||||
pmoserver = { path = "../pmoserver", optional = true }
|
||||
pmoconfig = { path = "../pmoconfig", optional = true }
|
||||
|
||||
@@ -68,8 +68,52 @@ pub use openapi::ApiDoc;
|
||||
#[cfg(feature = "pmoconfig")]
|
||||
pub use config_ext::CoverCacheConfigExt;
|
||||
|
||||
#[cfg(feature = "pmoserver")]
|
||||
// ============================================================================
|
||||
// Registre global singleton
|
||||
// ============================================================================
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
static COVER_CACHE: OnceCell<Arc<Cache>> = OnceCell::new();
|
||||
|
||||
/// Enregistre le cache de couvertures global
|
||||
///
|
||||
/// Cette fonction doit être appelée au démarrage de l'application
|
||||
/// pour rendre le cache de couvertures disponible globalement.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// use pmocovers::{new_cache, register_cover_cache};
|
||||
/// use std::sync::Arc;
|
||||
///
|
||||
/// let cache = Arc::new(new_cache("./covers", 100)?);
|
||||
/// register_cover_cache(cache);
|
||||
/// ```
|
||||
pub fn register_cover_cache(cache: Arc<Cache>) {
|
||||
let _ = COVER_CACHE.set(cache);
|
||||
}
|
||||
|
||||
/// Accès global au cache de couvertures
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// use pmocovers::get_cover_cache;
|
||||
///
|
||||
/// if let Some(cache) = get_cover_cache() {
|
||||
/// // Utiliser le cache
|
||||
/// }
|
||||
/// ```
|
||||
pub fn get_cover_cache() -> Option<Arc<Cache>> {
|
||||
COVER_CACHE.get().cloned()
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Extension pmoserver
|
||||
// ============================================================================
|
||||
|
||||
#[cfg(feature = "pmoserver")]
|
||||
use utoipa::OpenApi;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user