pub struct EffectiveExpiry;Expand description
Stateless calculator for effective expiry decisions.
All methods are pure: they take inputs by value/reference, do no I/O,
and never read the system clock. The caller is responsible for supplying
a monotonically-correct now_unix_ms.
Implementations§
Source§impl EffectiveExpiry
impl EffectiveExpiry
Sourcepub fn compute(
hard_expires_at_unix_ms: Option<u64>,
now_unix_ms: u64,
last_access_unix_ms: u64,
extended: &ExtendedTtlPolicy,
) -> ExpiryDecision
pub fn compute( hard_expires_at_unix_ms: Option<u64>, now_unix_ms: u64, last_access_unix_ms: u64, extended: &ExtendedTtlPolicy, ) -> ExpiryDecision
Compute the effective expiry decision for a cache entry.
§Arguments
hard_expires_at_unix_ms— pre-computed hard expiry from the baseBlobCachePolicy.Nonemeans “no hard expiry” (entry never hard-expires; only idle TTL can kill it).now_unix_ms— current time, supplied by caller.last_access_unix_ms— wall-clock time of the most recent access.extended— extended policy knobs.
§Decision Order
- Idle TTL — if configured and
now - last_access > idle_ttl, returnExpiredregardless of hard expiry. Idle is checked first because an idle-killed entry is dead even within its hard window. - No hard expiry — if
hard_expires_at_unix_msisNone, the only remaining gate is idle (already passed) →Fresh. - Within hard expiry —
now <= hard→Fresh. - Within SWR window —
now <= hard + stale_serve_ms→Stale. - Otherwise →
Expired.
Sourcepub fn jittered_ttl_ms(base_ttl_ms: u64, jitter_pct: u8, seed: u64) -> u64
pub fn jittered_ttl_ms(base_ttl_ms: u64, jitter_pct: u8, seed: u64) -> u64
Compute a jittered TTL given a base TTL, a jitter percentage, and a deterministic seed.
Returns base_ttl_ms + base_ttl_ms * offset / 100 where offset
is in [0, jitter_pct] (clamped to 0..=100). When jitter_pct == 0
the result is exactly base_ttl_ms.
Uses a small LCG (Numerical Recipes constants) so callers can supply
any u64 seed (entry hash, write timestamp, etc.) without needing
rand. Same seed + same inputs → same result, always.
Saturates on overflow rather than panicking.
Auto Trait Implementations§
impl Freeze for EffectiveExpiry
impl RefUnwindSafe for EffectiveExpiry
impl Send for EffectiveExpiry
impl Sync for EffectiveExpiry
impl Unpin for EffectiveExpiry
impl UnsafeUnpin for EffectiveExpiry
impl UnwindSafe for EffectiveExpiry
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request