pub struct ArtifactCache { /* private fields */ }Expand description
Budgeted, pin-aware view of the verified artifacts of one exchange.
Implementations§
Source§impl ArtifactCache
impl ArtifactCache
Sourcepub fn new(ex: Arc<ArtifactExchange>, cfg: CacheConfig) -> Arc<Self> ⓘ
pub fn new(ex: Arc<ArtifactExchange>, cfg: CacheConfig) -> Arc<Self> ⓘ
Cache over ex. The exchange reports every artifact that becomes
verified (seeded or fetched) to the cache, and the cache enforces
the budget as they arrive. Artifacts already verified are admitted.
Sourcepub fn exchange(&self) -> &Arc<ArtifactExchange> ⓘ
pub fn exchange(&self) -> &Arc<ArtifactExchange> ⓘ
The exchange this cache accounts.
Sourcepub fn admit(&self, id: &ArtifactId) -> Result<Vec<ArtifactId>, CacheError>
pub fn admit(&self, id: &ArtifactId) -> Result<Vec<ArtifactId>, CacheError>
Account for verified artifact id and enforce the budget. Returns
the artifacts evicted to make room. An unpinned artifact larger than
the whole budget is evicted again and reported as an error.
Sourcepub fn touch(&self, id: &ArtifactId)
pub fn touch(&self, id: &ArtifactId)
Mark id as just used.
Sourcepub fn pin(&self, id: &ArtifactId) -> bool
pub fn pin(&self, id: &ArtifactId) -> bool
Protect id from eviction. False if it is not in the cache.
Sourcepub fn unpin(&self, id: &ArtifactId) -> bool
pub fn unpin(&self, id: &ArtifactId) -> bool
Make id evictable again, then enforce the budget (it may go now).
Sourcepub fn pin_content(&self, content_hash: [u8; 32])
pub fn pin_content(&self, content_hash: [u8; 32])
Pin whatever has this content hash, now or the moment it arrives. A fetch admits an artifact as soon as it verifies, so a caller about to run a package pins its hashes first, or an over-budget cache could evict the artifact before the caller can pin it.
Sourcepub fn unpin_content(&self, content_hash: &[u8; 32])
pub fn unpin_content(&self, content_hash: &[u8; 32])
Undo Self::pin_content and make matching entries evictable again.
Sourcepub fn pin_package(&self, pkg: &ExchangedPackage)
pub fn pin_package(&self, pkg: &ExchangedPackage)
Pin a package’s manifest and every file it lists.
Sourcepub fn unpin_package(&self, pkg: &ExchangedPackage)
pub fn unpin_package(&self, pkg: &ExchangedPackage)
Make a package’s manifest and files evictable again (it was removed).
Sourcepub fn is_pinned(&self, id: &ArtifactId) -> bool
pub fn is_pinned(&self, id: &ArtifactId) -> bool
True if id is pinned.
Sourcepub fn set_kind(&self, id: &ArtifactId, kind: ArtifactKind) -> bool
pub fn set_kind(&self, id: &ArtifactId, kind: ArtifactKind) -> bool
Set what id is (for model.present).
Sourcepub fn remove(&self, id: &ArtifactId) -> Result<(), CacheError>
pub fn remove(&self, id: &ArtifactId) -> Result<(), CacheError>
Evict id now. Pinned entries are refused.
Sourcepub fn enforce(&self) -> Vec<ArtifactId>
pub fn enforce(&self) -> Vec<ArtifactId>
Evict least-recently-used unpinned entries until the total fits the budget. Returns the evicted ids, oldest first.
Sourcepub fn used_bytes(&self) -> u64
pub fn used_bytes(&self) -> u64
Bytes accounted: verified entries plus downloads in progress.
Sourcepub fn over_budget(&self) -> u64
pub fn over_budget(&self) -> u64
Bytes over the budget (only pins and downloads in progress can cause this).
Sourcepub fn entries(&self) -> Vec<CacheEntryInfo>
pub fn entries(&self) -> Vec<CacheEntryInfo>
Entries, least recently used first.
Auto Trait Implementations§
impl !Freeze for ArtifactCache
impl !RefUnwindSafe for ArtifactCache
impl !UnwindSafe for ArtifactCache
impl Send for ArtifactCache
impl Sync for ArtifactCache
impl Unpin for ArtifactCache
impl UnsafeUnpin for ArtifactCache
Blanket Implementations§
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