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
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.
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.
Implementations§
Source§impl CachePolicy
impl CachePolicy
Sourcepub fn validate(&self) -> Result<(), String>
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());Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Does the policy keep anything?
Sourcepub fn max_entries(&self) -> Option<usize>
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));Sourcepub fn ttl_seconds(&self) -> Option<u64>
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);Sourcepub fn summary(&self) -> String
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
impl Clone for CachePolicy
Source§fn clone(&self) -> CachePolicy
fn clone(&self) -> CachePolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for CachePolicy
Source§impl Debug for CachePolicy
impl Debug for CachePolicy
Source§impl<'de> Deserialize<'de> for CachePolicy
impl<'de> Deserialize<'de> for CachePolicy
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for CachePolicy
Source§impl JsonSchema for CachePolicy
impl JsonSchema for CachePolicy
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl PartialEq for CachePolicy
impl PartialEq for CachePolicy
Source§fn eq(&self, other: &CachePolicy) -> bool
fn eq(&self, other: &CachePolicy) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for CachePolicy
impl Serialize for CachePolicy
impl StructuralPartialEq for CachePolicy
Auto Trait Implementations§
impl Freeze for CachePolicy
impl RefUnwindSafe for CachePolicy
impl Send for CachePolicy
impl Sync for CachePolicy
impl Unpin for CachePolicy
impl UnsafeUnpin for CachePolicy
impl UnwindSafe for CachePolicy
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.