vyre_runtime/pipeline_cache/store.rs
1//! [`PipelineCacheStore`] - backend trait shared by every concrete cache
2//! implementation in this module.
3
4use std::io;
5use std::sync::Arc;
6
7use super::fingerprint::PipelineFingerprint;
8use super::metrics::PipelineCacheMetrics;
9
10/// Trait for persistent pipeline-cache backends. [`super::DiskCache`] and
11/// `super::RemoteCache` (when the `remote` feature is enabled) ship
12/// disk- and network-backed implementations; tests here use the
13/// in-memory [`super::InMemoryPipelineCache`].
14pub trait PipelineCacheStore: Send + Sync {
15 /// Look up a cached artifact for this fingerprint.
16 ///
17 /// This method is required so cache implementations cannot accidentally
18 /// inherit a mutually recursive `get` / `get_arc` pair. Hot-path consumers
19 /// should call [`Self::get_arc`] when they can share the payload.
20 fn get(&self, fp: &PipelineFingerprint) -> Option<Vec<u8>>;
21
22 /// V7-PERF-009: zero-clone hot-path lookup. Returns the cached artifact as
23 /// an `Arc<Vec<u8>>` so multiple consumers share the underlying allocation.
24 /// Default impl wraps `get`; in-memory and layered caches override this to
25 /// return their internal `Arc` directly.
26 fn get_arc(&self, fp: &PipelineFingerprint) -> Option<Arc<Vec<u8>>> {
27 self.get(fp).map(Arc::new)
28 }
29
30 /// Insert a pre-compiled artifact. Implementations may dedupe
31 /// or evict per their own policy.
32 fn put(&self, fp: PipelineFingerprint, artifact: Vec<u8>);
33
34 /// Durably flush artifacts that were accepted by [`Self::put`].
35 ///
36 /// Volatile stores can keep the default no-op. Disk stores override this
37 /// so insertion stays cheap while callers still have an explicit
38 /// crash-durable boundary.
39 ///
40 /// # Errors
41 ///
42 /// Returns an I/O error when a durable backend cannot flush pending data.
43 fn flush(&self) -> io::Result<()> {
44 Ok(())
45 }
46
47 /// Snapshot cache instrumentation for latency, throughput, and eviction
48 /// gates. Backends that do not maintain counters return zeros.
49 #[must_use]
50 fn metrics(&self) -> PipelineCacheMetrics {
51 PipelineCacheMetrics::default()
52 }
53}