use crate::Result;
use crate::plugins::{PostProcessor, ProcessingStage};
use parking_lot::RwLock;
use std::sync::Arc;
use std::sync::LazyLock;
pub(super) struct ProcessorCache {
pub(super) early: Arc<Vec<Arc<dyn PostProcessor>>>,
pub(super) middle: Arc<Vec<Arc<dyn PostProcessor>>>,
pub(super) late: Arc<Vec<Arc<dyn PostProcessor>>>,
}
impl ProcessorCache {
pub(super) fn new() -> Result<Self> {
let processor_registry = crate::plugins::registry::get_post_processor_registry();
let registry = processor_registry.read();
Ok(Self {
early: Arc::new(registry.get_for_stage(ProcessingStage::Early)),
middle: Arc::new(registry.get_for_stage(ProcessingStage::Middle)),
late: Arc::new(registry.get_for_stage(ProcessingStage::Late)),
})
}
}
pub(super) static PROCESSOR_CACHE: LazyLock<RwLock<Option<ProcessorCache>>> = LazyLock::new(|| RwLock::new(None));
pub fn clear_processor_cache() -> Result<()> {
let mut cache = PROCESSOR_CACHE.write();
*cache = None;
Ok(())
}