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
impl Policy
Sourcepub fn enabled(ttl_sec: u64) -> Self
pub fn enabled(ttl_sec: u64) -> Self
Both serving layers enabled with the same TTL and full ramps.
Sourcepub fn disabled() -> Self
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.
Sourcepub fn request_local(self, enabled: bool) -> Self
pub fn request_local(self, enabled: bool) -> Self
Set whether values are memoized for the outermost enabled scope.
Sourcepub fn coalesce(self, enabled: bool) -> Self
pub fn coalesce(self, enabled: bool) -> Self
Set whether concurrent same-key callers share one execution.
Sourcepub fn local_ttl_sec(self, ttl_sec: u64) -> Self
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.
Sourcepub fn remote_ttl_sec(self, ttl_sec: u64) -> Self
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.
Sourcepub fn local_ramp(self, ramp: f64) -> Self
pub fn local_ramp(self, ramp: f64) -> Self
Set the process-local serving cohort percentage, 0.0..=100.0.
Sourcepub fn remote_ramp(self, ramp: f64) -> Self
pub fn remote_ramp(self, ramp: f64) -> Self
Set the remote serving cohort percentage, 0.0..=100.0.
Sourcepub fn stale_on_error_max_age_sec(self, seconds: u64) -> Self
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.
Sourcepub fn remote_read_timeout_ms(self, ms: u64) -> Self
pub fn remote_read_timeout_ms(self, ms: u64) -> Self
Set the remote read budget in milliseconds, overriding the instance default.
Sourcepub fn shadow(self, shadow: ShadowPolicy) -> Self
pub fn shadow(self, shadow: ShadowPolicy) -> Self
Set the shadow validation policy.
Sourcepub fn from_json(value: &Value) -> Result<Policy, PolicyError>
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.
Sourcepub fn to_json(&self) -> Value
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.
Sourcepub fn validate(&self) -> Result<(), PolicyError>
pub fn validate(&self) -> Result<(), PolicyError>
Reject statically invalid leaves.