Skip to main content

CachePolicy

Enum CachePolicy 

Source
pub enum CachePolicy {
    Disabled,
    Process {
        max_entries: usize,
        ttl_seconds: Option<u64>,
    },
    Generation {
        max_entries: usize,
    },
    Checkout {
        max_entries: usize,
    },
}
Expand description

Whether, and how, the executor keeps results of this capability. Cache lives in the executor and nowhere else, so MCP, HTTP and the command line share one; the key is the canonical id, the normalised input and the registry fingerprint, so a changed repository never answers from an old entry. The two narrower policies add to the key what the registry fingerprint cannot see: the context’s own reading of the repository (CachePolicy::Generation) and the state of the checkout itself (CachePolicy::Checkout).

Variants§

§

Disabled

Every call runs the handler.

§

Process

Results are kept in this process’s memory, bounded, for equal inputs.

Fields

§max_entries: usize

The most entries kept for this capability; the oldest is evicted first.

§ttl_seconds: Option<u64>

Seconds an entry stays valid; None for the life of the process.

§

Generation

Results are kept for equal inputs while the context that computed them is the one asked: for a capability that is a function of the index and the registry alone, including the git state the index was read at, which the registry fingerprint does not cover. A reload of the repository is a new context, and so a new key.

Fields

§max_entries: usize

The most entries kept for this capability; the oldest is evicted first.

§

Checkout

Results are kept for equal inputs while the context is the same and the checkout is as it was: HEAD, the staging index, the refs and every changed or untracked path of the work tree, fingerprinted again on every call (capability::checkout). For a capability that reads git, the index and the files of the work tree, and nothing that fingerprint cannot see: no ignored file, no other process, no network, no clock. A checkout git cannot fingerprint is not cached.

Fields

§max_entries: usize

The most entries kept for this capability; the oldest is evicted first.

Implementations§

Source§

impl CachePolicy

Source

pub fn validate(&self) -> Result<(), String>

Is the policy well-formed? The reason when it is not.

use majordomus_cli::capability::CachePolicy;
assert!(CachePolicy::Disabled.validate().is_ok());
assert!(CachePolicy::Process { max_entries: 0, ttl_seconds: None }.validate().is_err());
assert!(CachePolicy::Checkout { max_entries: 0 }.validate().is_err());
assert!(CachePolicy::Generation { max_entries: 4 }.validate().is_ok());
Source

pub fn is_enabled(&self) -> bool

Does the policy keep anything?

Source

pub fn max_entries(&self) -> Option<usize>

The most entries the policy keeps per capability; None when it keeps nothing.

use majordomus_cli::capability::CachePolicy;
assert_eq!(CachePolicy::Disabled.max_entries(), None);
assert_eq!(CachePolicy::Checkout { max_entries: 2 }.max_entries(), Some(2));
Source

pub fn ttl_seconds(&self) -> Option<u64>

Seconds an entry stays valid; None for as long as its key holds.

use majordomus_cli::capability::CachePolicy;
let p = CachePolicy::Process { max_entries: 2, ttl_seconds: Some(5) };
assert_eq!(p.ttl_seconds(), Some(5));
assert_eq!(CachePolicy::Generation { max_entries: 2 }.ttl_seconds(), None);
Source

pub fn summary(&self) -> String

The policy in a few words, as the Cockpit and the generated catalogue print it.

use majordomus_cli::capability::CachePolicy;
assert_eq!(CachePolicy::Disabled.summary(), "—");
assert_eq!(
    CachePolicy::Process { max_entries: 8, ttl_seconds: Some(5) }.summary(),
    "process, 8 entries, 5s"
);
assert_eq!(
    CachePolicy::Checkout { max_entries: 4 }.summary(),
    "process, 4 entries, per checkout state"
);

Trait Implementations§

Source§

impl Clone for CachePolicy

Source§

fn clone(&self) -> CachePolicy

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
Source§

impl Copy for CachePolicy

Source§

impl Debug for CachePolicy

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for CachePolicy

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for CachePolicy

Source§

impl JsonSchema for CachePolicy

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for CachePolicy

Source§

fn eq(&self, other: &CachePolicy) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for CachePolicy

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CachePolicy

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
§

impl<T> AsOut<T> for T
where T: Copy,

§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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