pub struct SnapshotCache { /* private fields */ }Expand description
Thread-safe snapshot cache keyed by bridge code digest.
Uses two-phase locking with per-key in-flight tracking so concurrent callers requesting different bridge code variants are not blocked by each other. Callers requesting the same variant wait on a condvar instead of creating duplicate snapshots.
Implementations§
Source§impl SnapshotCache
impl SnapshotCache
pub fn new(max_entries: usize) -> Self
Sourcepub fn get_or_create(&self, bridge_code: &str) -> Result<Arc<Vec<u8>>, String>
pub fn get_or_create(&self, bridge_code: &str) -> Result<Arc<Vec<u8>>, String>
Get or create a snapshot for the given bridge code.
Two-phase locking: the cache mutex is held only for lookups and inserts, never during snapshot creation. Per-key in-flight tracking prevents duplicate snapshot creation for the same bridge code.
Sourcepub fn try_get_with_userland(
&self,
bridge_code: &str,
userland_code: Option<&str>,
) -> Option<Arc<Vec<u8>>>
pub fn try_get_with_userland( &self, bridge_code: &str, userland_code: Option<&str>, ) -> Option<Arc<Vec<u8>>>
Return a cached snapshot if present. This never creates a snapshot or waits on in-flight creation.
Sourcepub fn get_or_create_with_userland(
&self,
bridge_code: &str,
userland_code: Option<&str>,
) -> Result<Arc<Vec<u8>>, String>
pub fn get_or_create_with_userland( &self, bridge_code: &str, userland_code: Option<&str>, ) -> Result<Arc<Vec<u8>>, String>
Like [get_or_create], but the snapshot also captures an evaluated userland
(agent-SDK) graph. The cache key is the digest of BOTH bridge_code and
userland_code, so a change to either — i.e. any change in the bundled
dependency graph — invalidates the entry and triggers exactly one rebuild.