pub struct RootfsCache { /* private fields */ }Expand description
Cache for fully-built rootfs directories.
Rootfs entries are stored under cache_dir/rootfs/<key>/.
Metadata is stored alongside as <key>.meta.json.
Implementations§
Source§impl RootfsCache
impl RootfsCache
Sourcepub fn compute_key(
image_ref: &str,
layer_digests: &[String],
entrypoint: &[String],
env: &[(String, String)],
) -> String
pub fn compute_key( image_ref: &str, layer_digests: &[String], entrypoint: &[String], env: &[(String, String)], ) -> String
Compute a cache key from image components.
The key is a SHA256 hash of the concatenation of:
- image reference (e.g., “nginx:latest”)
- sorted layer digests
- entrypoint
- sorted environment variables
Sourcepub fn get(&self, key: &str) -> Result<Option<PathBuf>>
pub fn get(&self, key: &str) -> Result<Option<PathBuf>>
Get the path to a cached rootfs by key.
Returns None if the rootfs is not cached or the cache entry is invalid.
Sourcepub fn put(
&self,
key: &str,
source_rootfs: &Path,
description: &str,
) -> Result<PathBuf>
pub fn put( &self, key: &str, source_rootfs: &Path, description: &str, ) -> Result<PathBuf>
Store a built rootfs directory in the cache.
Copies the contents of source_rootfs into the cache keyed by key.
Returns the path to the cached rootfs directory.
Sourcepub fn invalidate(&self, key: &str) -> Result<()>
pub fn invalidate(&self, key: &str) -> Result<()>
Remove a cached rootfs by key.
Sourcepub fn prune(&self, max_entries: usize, max_bytes: u64) -> Result<usize>
pub fn prune(&self, max_entries: usize, max_bytes: u64) -> Result<usize>
Prune the cache to stay within the given entry count / byte limit.
Evicts least-recently-accessed entries first. Returns the number evicted.
Sourcepub fn prune_protecting(
&self,
max_entries: usize,
max_bytes: u64,
protected: &HashSet<String>,
) -> Result<usize>
pub fn prune_protecting( &self, max_entries: usize, max_bytes: u64, protected: &HashSet<String>, ) -> Result<usize>
Like RootfsCache::prune, but never evicts an entry whose key is in
protected. Such an entry is currently serving as a box’s overlayfs
lowerdir, and remove_dir_all-ing it out from under a concurrent box’s
mount(2) makes the mount fail with ENOENT (“No such file or directory”).
This is the same in-use guard crate::SnapshotStore::prune applies to
live copy-on-write lowers — without it, two pipelines built from the same
image (one cache-hit overlay box, one cache-miss box that prunes after its
put) can race and corrupt each other.
Sourcepub fn list_entries(&self) -> Result<Vec<RootfsMeta>>
pub fn list_entries(&self) -> Result<Vec<RootfsMeta>>
List all cached rootfs entries with their metadata.
Sourcepub fn total_size(&self) -> Result<u64>
pub fn total_size(&self) -> Result<u64>
Get the total size of all cached rootfs entries in bytes.
Sourcepub fn entry_count(&self) -> Result<usize>
pub fn entry_count(&self) -> Result<usize>
Get the number of cached rootfs entries.
Trait Implementations§
Source§impl CacheBackend for RootfsCache
impl CacheBackend for RootfsCache
Source§fn get(&self, key: &str) -> Result<Option<PathBuf>>
fn get(&self, key: &str) -> Result<Option<PathBuf>>
Source§fn put(
&self,
key: &str,
source_dir: &Path,
description: &str,
) -> Result<PathBuf>
fn put( &self, key: &str, source_dir: &Path, description: &str, ) -> Result<PathBuf>
Auto Trait Implementations§
impl Freeze for RootfsCache
impl RefUnwindSafe for RootfsCache
impl Send for RootfsCache
impl Sync for RootfsCache
impl Unpin for RootfsCache
impl UnsafeUnpin for RootfsCache
impl UnwindSafe for RootfsCache
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more