Skip to main content

CacheAgent

Struct CacheAgent 

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

Shared state for an agent hosted by the process that owns a build session.

Transport listeners deliberately live in the embedder so the session lifecycle owns them. This type only contains ecosystem-independent CAS and protocol logic.

Implementations§

Source§

impl CacheAgent

Source

pub fn new(cache_dir: impl Into<PathBuf>, version: impl Into<Arc<str>>) -> Self

Create an agent backed by the cache rooted at cache_dir.

Source

pub fn new_remote( cache_dir: impl Into<PathBuf>, version: impl Into<Arc<str>>, remote: AgentRemoteCache, ) -> Self

Create an agent with local-first access to a remote action cache.

Source

pub fn new_remote_with_download_limit( cache_dir: impl Into<PathBuf>, version: impl Into<Arc<str>>, remote: AgentRemoteCache, max_remote_download_bytes: u64, ) -> Self

Create a remote agent with a cumulative download budget for the session.

Source

pub fn with_observer(self, observer: Arc<dyn AgentEventObserver>) -> Self

Report each accounted cache decision to observer as it happens.

Source

pub fn with_task_loader( self, loader: Arc<dyn for<'a> Fn(&'a CacheAgent, &'a str) -> BoxFuture<'a, ()> + Send + Sync>, ) -> Self

Load tasks on demand.

The loader is called with the agent and the task’s identity before the first request that names a task this agent has not begun, and is expected to begin it; a second call for the same task must be a no-op. Requests that name no task never wait on it.

Source

pub async fn begin_task(&self, task: &str) -> Result<String>

Load the last committed action manifest for a task into this session.

Source

pub async fn begin_task_on_prediction(&self, task: &str) -> Result<String>

Load a task but defer each adapter’s speculative downloads until its first prediction matches the current build.

Source

pub async fn begin_session_task(&self, task: &str) -> Result<()>

Load a task using its identity as the run key.

A task-scoped process has only one run for an identity, so it can defer this work until its first client connects while putting the identity in the client’s environment ahead of time.

Source

pub fn register_task_fallbacks( &self, task: &str, fallbacks: impl Fn() -> Vec<String> + Send + Sync + 'static, ) -> Result<()>

Name where a task’s predictions may come from when nothing has been recorded under its own identity.

The identities are produced on demand rather than taken up front, because finding them can cost a few version-control commands and most builds never need them. The first manifest found, locally and then on the remote, is adopted under the task’s own identity, so the commands that follow, tests and lints included, start from it too, and a trusted build publishes it there. When none of the named identities has one, the store’s newest manifests are tried.

Source

pub async fn prefetch_task(&self, task: &str) -> Result<String>

Load a task and finish its prefetch, surfacing remote lookup failures.

Source

pub async fn cancel_prefetches(&self)

Cancel speculative downloads before the owning session exits.

Source

pub async fn wait_for_uploads(&self)

Publish everything a build queued, before the session stops.

Store requests return once an object is durable locally, so at this point the remote cache may still be behind the local one. Uploads run on the session’s runtime and are abandoned if it goes away, so a session that wants them published has to wait here.

Source

pub async fn commit_task(&self, run: &str) -> Result<()>

Atomically publish the completed actions collected by a task run.

Source

pub async fn commit_task_actions( &self, run: &str, ) -> Result<Vec<ActionPrediction>>

Publish a task run and return exactly the predictions completed by it.

The persisted task manifest also carries predictions inherited from earlier runs. Callers that need a receipt for this one run must not mistake that cumulative manifest for the work the run completed.

Source

pub fn stats(&self) -> AgentStats

Return a snapshot of this session’s cache activity.

Source

pub async fn handle_requests( &self, requests: impl IntoIterator<Item = AgentRequest>, ) -> Vec<AgentResponse>

Handle requests without a transport connection.

Persistent wrappers use this entry point when Cargo invokes mbx outside an orchestrated session. It intentionally has the same response semantics as Self::handle_connection, while leaving framing and the version handshake to callers that actually cross a process boundary.

Source

pub fn seed_file_digests( &self, entries: Vec<(FileDigestScope, RecordedFileDigest)>, ) -> usize

Start the file-digest ledger from entries an earlier session left behind, so a file nothing has touched since is not read again by the first compilation of this session that names it.

Each entry stands only while its recorded identity still matches the disk, the same rule a lookup applies to what this session recorded, so a stale seed costs a hash and nothing else. Entries this session has already recorded are kept over seeded ones. Returns how many were taken.

Source

pub fn seed_file_digests_with( &self, load: impl FnOnce() -> Vec<(FileDigestScope, RecordedFileDigest)>, ) -> usize

Seed the ledger from entries produced under its lock.

A lookup that arrives while load is still reading waits for it rather than missing, so a caller can start the read in the background and let whatever else the build is doing overlap it.

Source

pub fn file_digests(&self) -> Vec<(FileDigestScope, RecordedFileDigest)>

Everything the file-digest ledger holds, for a later session to start from.

Source

pub async fn handle_connection<S>(&self, stream: S) -> Result<()>
where S: AsyncRead + AsyncWrite + Unpin,

Serve newline-delimited protocol requests on an authenticated session stream.

Trait Implementations§

Source§

impl Clone for CacheAgent

Source§

fn clone(&self) -> CacheAgent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: Sized + 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: Sized + 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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