Struct Cache

Source
pub struct Cache { /* private fields */ }
Expand description

Docker 镜像缓存管理

提供本地缓存功能,结构与 Docker Registry API 兼容,支持从 repository 或 tar 文件 获取 manifest 和 blob,并支持从缓存中推送。

缓存结构:

.cache/
  manifests/{repository}/{reference}
  blobs/sha256/{digest}
  index.json  // 缓存索引

Implementations§

Source§

impl Cache

Source

pub fn new<P: AsRef<Path>>(cache_dir: Option<P>) -> Result<Self>

创建新的缓存管理器

Source

pub fn save_manifest( &mut self, repository: &str, reference: &str, manifest: &[u8], config_digest: &str, ) -> Result<PathBuf>

保存清单(manifest)到缓存

Source

pub fn save_blob( &mut self, digest: &str, data: &[u8], _is_config: bool, _compressed: bool, ) -> Result<PathBuf>

保存 blob 到缓存

Source

pub fn associate_blob_with_image( &mut self, repository: &str, reference: &str, digest: &str, size: u64, is_config: bool, compressed: bool, ) -> Result<()>

将 blob 关联到指定的镜像

Source

pub fn add_blob( &mut self, digest: &str, data: &[u8], _is_config: bool, _compressed: bool, ) -> Result<PathBuf>

Add a blob to the cache

Source

pub fn get_blob_path(&self, digest: &str) -> PathBuf

Get blob path from digest

Source

pub fn has_blob(&self, digest: &str) -> bool

Check if a blob exists in cache

Source

pub fn get_manifest(&self, repository: &str, reference: &str) -> Result<Vec<u8>>

从缓存中获取 manifest

Source

pub fn get_blob(&self, digest: &str) -> Result<Vec<u8>>

从缓存中获取 blob

Source

pub fn remove_manifest( &mut self, repository: &str, reference: &str, ) -> Result<()>

删除清单及其未被其他镜像引用的 blob

Source

pub fn list_manifests(&self) -> Vec<(String, String)>

列出缓存中的所有清单

Source

pub fn get_stats(&self) -> Result<CacheStats>

获取缓存统计信息

Source

pub fn get_blob_size(&self, digest: &str) -> Option<u64>

从缓存中获取blob大小

Source

pub fn get_image_blobs( &self, repository: &str, reference: &str, ) -> Result<Vec<BlobInfo>>

获取镜像的所有blob信息

Source

pub fn is_image_complete( &self, repository: &str, reference: &str, ) -> Result<bool>

检查镜像是否完整(manifest和所有blob都存在)

Source

pub fn cache_from_tar( &mut self, tar_path: &Path, repository: &str, reference: &str, ) -> Result<()>

从tar文件中提取blob信息并缓存

Auto Trait Implementations§

§

impl Freeze for Cache

§

impl RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,