pub trait CacheBackend: Send + Sync {
// Required methods
fn get(&self, key: &str) -> Result<Option<PathBuf>>;
fn put(
&self,
key: &str,
source_dir: &Path,
description: &str,
) -> Result<PathBuf>;
fn invalidate(&self, key: &str) -> Result<()>;
fn prune(&self, max_entries: usize, max_bytes: u64) -> Result<usize>;
fn list(&self) -> Result<Vec<CacheEntry>>;
// Provided method
fn stats(&self) -> Result<CacheStats> { ... }
}Expand description
Abstraction over directory-based caching.
Used for both OCI layer caching and fully-built rootfs caching. The key is an opaque string (typically a content hash), and the value is a directory tree on disk.
§Lifecycle
get(key)— check if a cached directory exists for this key- On miss: build the content, then
put(key, source_dir, desc) prune(max_entries, max_bytes)— evict old entries to stay within limits
§Thread Safety
Implementations must be Send + Sync. Concurrent get/put calls
with different keys must be safe. Concurrent calls with the same key
have implementation-defined behavior (last writer wins is acceptable).
Required Methods§
Sourcefn get(&self, key: &str) -> Result<Option<PathBuf>>
fn get(&self, key: &str) -> Result<Option<PathBuf>>
Retrieve a cached directory by key.
Returns Some(path) if the key exists and the cached content is valid.
The returned path points to a directory that the caller can read from.
Returns None on cache miss.
Implementations should update the last-accessed timestamp on hit.
Sourcefn put(
&self,
key: &str,
source_dir: &Path,
description: &str,
) -> Result<PathBuf>
fn put( &self, key: &str, source_dir: &Path, description: &str, ) -> Result<PathBuf>
Store a directory tree in the cache under the given key.
Copies (or moves) the contents of source_dir into the cache.
If an entry with this key already exists, it is replaced.
Returns the path to the cached directory (which may differ from source_dir).
Sourcefn invalidate(&self, key: &str) -> Result<()>
fn invalidate(&self, key: &str) -> Result<()>
Remove a cached entry by key.
No-op if the key does not exist.
Sourcefn prune(&self, max_entries: usize, max_bytes: u64) -> Result<usize>
fn prune(&self, max_entries: usize, max_bytes: u64) -> Result<usize>
Evict entries to satisfy the given constraints.
Implementations should evict least-recently-accessed entries first. Returns the number of entries evicted.
Sourcefn list(&self) -> Result<Vec<CacheEntry>>
fn list(&self) -> Result<Vec<CacheEntry>>
List all cache entries with their metadata.
Provided Methods§
Sourcefn stats(&self) -> Result<CacheStats>
fn stats(&self) -> Result<CacheStats>
Get aggregate cache statistics.