pub struct Cache<FsT: Fs, KeyT: Key, GetStrategyT: GetStrategy> { /* private fields */ }Expand description
Manage a directory of downloaded, extracted artifacts. Coordinate fetching of these artifacts, and removing them when they are no longer in use and the amount of space used by the directory has grown too large.
Implementations§
Source§impl<FsT: Fs, KeyT: Key, GetStrategyT: GetStrategy> Cache<FsT, KeyT, GetStrategyT>
impl<FsT: Fs, KeyT: Key, GetStrategyT: GetStrategy> Cache<FsT, KeyT, GetStrategyT>
Sourcepub fn new(
fs: FsT,
root: RootBuf<CacheDir>,
size: CacheSize,
log: Logger,
log_initial_message_at_info: bool,
) -> Result<(Self, TempFileFactory<FsT>)>
pub fn new( fs: FsT, root: RootBuf<CacheDir>, size: CacheSize, log: Logger, log_initial_message_at_info: bool, ) -> Result<(Self, TempFileFactory<FsT>)>
Create a new Cache rooted at root. The directory root and all necessary ancestors
will be created, along with {root}/removing and {root}/{kind}/sha256. Any pre-existing
entries in {root}/removing and {root}/{kind}/sha256 will be removed. That implies that
the Cache doesn’t currently keep data stored across invocations.
bytes_used_target is the goal on-disk size for the cache. The cache will periodically grow
larger than this size, but then shrink back down to this size. Ideally, the cache would use
this as a hard upper bound, but that’s not how it currently works.
Sourcepub fn get_artifact(&mut self, key: KeyT, jid: JobId) -> GetArtifact
pub fn get_artifact(&mut self, key: KeyT, jid: JobId) -> GetArtifact
Attempt to fetch artifact from the cache. See GetArtifact for the meaning of the
return values.
Sourcepub fn got_artifact_failure(&mut self, key: &KeyT) -> Vec<JobId>
pub fn got_artifact_failure(&mut self, key: &KeyT) -> Vec<JobId>
Notify the cache that an artifact fetch has failed. The returned vector lists the jobs that are affected and that need to be canceled.
Sourcepub fn got_artifact_success(
&mut self,
key: &KeyT,
artifact: GotArtifact<FsT>,
) -> Result<Vec<JobId>, (Error, Vec<JobId>)>
pub fn got_artifact_success( &mut self, key: &KeyT, artifact: GotArtifact<FsT>, ) -> Result<Vec<JobId>, (Error, Vec<JobId>)>
Notify the cache that an artifact fetch has successfully completed. The returned vector lists the jobs that are affected, and the path they can use to access the artifact.
Sourcepub fn try_increment_ref_count(&mut self, key: &KeyT) -> Option<u64>
pub fn try_increment_ref_count(&mut self, key: &KeyT) -> Option<u64>
Assuming that a reference count is already is already held for the artifact, increment it by one and return the size of the artifact. If no reference count is already held, return None.
Sourcepub fn try_get_size(&mut self, key: &KeyT) -> Option<u64>
pub fn try_get_size(&mut self, key: &KeyT) -> Option<u64>
Assuming that a reference count is already is already held for the artifact, return the size of the artifact, otherwise return None.
Sourcepub fn decrement_ref_count(&mut self, key: &KeyT)
pub fn decrement_ref_count(&mut self, key: &KeyT)
Notify the cache that a reference to an artifact is no longer needed.
pub fn getter_disconnected(&mut self, getter: GetStrategyT::Getter)
pub fn root(&self) -> &Root<CacheDir>
Sourcepub fn cache_path(&self, key: &KeyT) -> RootBuf<EntryPath>
pub fn cache_path(&self, key: &KeyT) -> RootBuf<EntryPath>
Return the directory path for the artifact referenced by digest.
Auto Trait Implementations§
impl<FsT, KeyT, GetStrategyT> Freeze for Cache<FsT, KeyT, GetStrategyT>
impl<FsT, KeyT, GetStrategyT> RefUnwindSafe for Cache<FsT, KeyT, GetStrategyT>where
FsT: RefUnwindSafe,
Map<KeyT, GetStrategyT>: RefUnwindSafe,
Heap<Map<KeyT, GetStrategyT>>: RefUnwindSafe,
<FsT as Fs>::FileLock: RefUnwindSafe,
impl<FsT, KeyT, GetStrategyT> Send for Cache<FsT, KeyT, GetStrategyT>
impl<FsT, KeyT, GetStrategyT> Sync for Cache<FsT, KeyT, GetStrategyT>
impl<FsT, KeyT, GetStrategyT> Unpin for Cache<FsT, KeyT, GetStrategyT>
impl<FsT, KeyT, GetStrategyT> UnsafeUnpin for Cache<FsT, KeyT, GetStrategyT>where
FsT: UnsafeUnpin,
Map<KeyT, GetStrategyT>: UnsafeUnpin,
Heap<Map<KeyT, GetStrategyT>>: UnsafeUnpin,
<FsT as Fs>::FileLock: UnsafeUnpin,
impl<FsT, KeyT, GetStrategyT> UnwindSafe for Cache<FsT, KeyT, GetStrategyT>where
FsT: UnwindSafe,
Map<KeyT, GetStrategyT>: UnwindSafe,
Heap<Map<KeyT, GetStrategyT>>: UnwindSafe,
<FsT as Fs>::FileLock: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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