Skip to main content

Policy

Struct Policy 

Source
pub struct Policy {
    pub request_local: Option<bool>,
    pub coalesce: Option<bool>,
    pub local_ttl_sec: Option<u64>,
    pub remote_ttl_sec: Option<u64>,
    pub local_ramp: Option<f64>,
    pub remote_ramp: Option<f64>,
    pub stale_on_error_max_age_sec: Option<u64>,
    pub remote_read_timeout_ms: Option<u64>,
    pub shadow: Option<ShadowPolicy>,
}
Expand description

Static caching policy of one operation. Omitted leaves use library defaults or are overridden by a runtime overlay.

Fields§

§request_local: Option<bool>

Memoize values for the outermost enabled scope. Defaults to false.

§coalesce: Option<bool>

Share one execution across concurrent same-key callers. Defaults to true.

§local_ttl_sec: Option<u64>

Process-local TTL in whole seconds, 1..=MAX_CACHE_TTL_SEC. Omitted disables the layer.

§remote_ttl_sec: Option<u64>

Remote TTL in whole seconds. Omitted disables the layer.

§local_ramp: Option<f64>

Local serving cohort percentage; a configured TTL implies 100.

§remote_ramp: Option<f64>

Remote serving cohort percentage; a configured TTL implies 100.

§stale_on_error_max_age_sec: Option<u64>

Exclusive stale-recovery age ceiling in seconds; must exceed the remote TTL. Zero disables.

§remote_read_timeout_ms: Option<u64>

Remote read budget in milliseconds, 1..=MAX_DEADLINE_MS.

§shadow: Option<ShadowPolicy>

Shadow validation cohort and warning policy. Omitted means no shadow work.

Implementations§

Source§

impl Policy

Source

pub fn enabled(ttl_sec: u64) -> Self

Both serving layers enabled with the same TTL and full ramps.

Source

pub fn disabled() -> Self

The explicit kill switch: request memoization, recovery and shadow work off, both serving layers ramped to zero. As an overlay it disables every inherited path instead of relying on omission.

Source

pub fn request_local(self, enabled: bool) -> Self

Set whether values are memoized for the outermost enabled scope.

Source

pub fn coalesce(self, enabled: bool) -> Self

Set whether concurrent same-key callers share one execution.

Source

pub fn local_ttl_sec(self, ttl_sec: u64) -> Self

Set the process-local TTL in whole seconds, enabling the layer with an implied full ramp.

Source

pub fn remote_ttl_sec(self, ttl_sec: u64) -> Self

Set the remote TTL in whole seconds, enabling the layer with an implied full ramp.

Source

pub fn local_ramp(self, ramp: f64) -> Self

Set the process-local serving cohort percentage, 0.0..=100.0.

Source

pub fn remote_ramp(self, ramp: f64) -> Self

Set the remote serving cohort percentage, 0.0..=100.0.

Source

pub fn stale_on_error_max_age_sec(self, seconds: u64) -> Self

Set the stale-recovery age ceiling in seconds. Zero disables recovery; a positive value must exceed the remote TTL.

Source

pub fn remote_read_timeout_ms(self, ms: u64) -> Self

Set the remote read budget in milliseconds, overriding the instance default.

Source

pub fn shadow(self, shadow: ShadowPolicy) -> Self

Set the shadow validation policy.

Source

pub fn from_json(value: &Value) -> Result<Policy, PolicyError>

Parse the JSON-shaped TypeScript configuration (ttlSec, ramp, shadow, requestLocal, coalesce, staleOnErrorMaxAgeSec, remoteReadTimeoutMs). null or absent means an empty policy.

A present leaf holding null is an invalid supplied value, not an omission: JSON has no way to spell JavaScript’s undefined, so every member of an object counts as present.

Source

pub fn to_json(&self) -> Value

The JSON-shaped form of this policy, with omitted leaves absent.

ttlSec and ramp are always objects (possibly empty). All other leaves, including requestLocal and coalesce, appear only when set, so converting this policy to a runtime overlay preserves inheritance.

Source

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

Reject statically invalid leaves.

Trait Implementations§

Source§

impl Clone for Policy

Source§

fn clone(&self) -> Policy

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 Debug for Policy

Source§

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

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

impl Default for Policy

Source§

fn default() -> Policy

Returns the “default value” for a type. Read more
Source§

impl From<Policy> for RuntimePolicy

Source§

fn from(policy: Policy) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Policy

Source§

fn eq(&self, other: &Policy) -> 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 StructuralPartialEq for Policy

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, 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> 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.