pub struct ImageRegistry { /* private fields */ }Expand description
Persistent LRU cache mapping opaque keys to SnapshotIds.
Backed by a single SQLite table with WAL journaling. The registry tracks
the last-access timestamp for every entry and evicts the oldest entries
when the configured capacity is exceeded.
The inner Connection is wrapped in a Mutex so that the registry
(and any struct containing it, e.g. crate::vm::HmVm) satisfies
Send + Sync for safe sharing across async tasks.
Implementations§
Source§impl ImageRegistry
impl ImageRegistry
Sourcepub fn open(path: &Path, capacity: NonZeroU64) -> Result<Self>
pub fn open(path: &Path, capacity: NonZeroU64) -> Result<Self>
Open or create the registry database at path.
The parent directory is created if it does not exist. The database uses
WAL mode and NORMAL synchronous for a good balance of durability and
performance.
§Errors
Returns an error if the database cannot be opened or the schema cannot be applied.
Sourcepub fn get(&self, key: &str) -> Option<SnapshotId>
pub fn get(&self, key: &str) -> Option<SnapshotId>
Look up a cached snapshot and update its access time.
Returns None if no entry exists for key.
Sourcepub fn put(&self, key: &str, snapshot: &SnapshotId) -> Vec<SnapshotId>
pub fn put(&self, key: &str, snapshot: &SnapshotId) -> Vec<SnapshotId>
Insert or update a cache entry.
Returns the SnapshotIds of any entries evicted to keep the registry
within its configured capacity. The caller is responsible for cleaning
up the backend resources associated with evicted snapshots.
Sourcepub fn invalidate(&self, key: &str) -> Option<SnapshotId>
pub fn invalidate(&self, key: &str) -> Option<SnapshotId>
Remove a specific entry.
Returns the removed snapshot’s ID so the caller can clean up backend
resources, or None if the key was not present.
Sourcepub fn all_snapshot_ids(&self) -> Vec<SnapshotId>
pub fn all_snapshot_ids(&self) -> Vec<SnapshotId>
Return every stored snapshot ID.
Used by hm cache clean to remove the backing backend images before
the registry DB is deleted — without this the images orphan beyond
recovery by key. Order is unspecified.