pub struct TtlEntry<V> {
pub value: V,
pub inserted_at_secs: u64,
pub ttl_secs: u64,
}Expand description
A single cache entry with an embedded TTL deadline.
Fields§
§value: VThe cached value.
inserted_at_secs: u64Epoch-seconds at which this entry was inserted.
ttl_secs: u64Lifetime in seconds from insertion.
Implementations§
Source§impl<V> TtlEntry<V>
impl<V> TtlEntry<V>
Sourcepub fn new(value: V, inserted_at_secs: u64, ttl_secs: u64) -> Self
pub fn new(value: V, inserted_at_secs: u64, ttl_secs: u64) -> Self
Create a new entry with the given parameters.
Sourcepub fn is_expired(&self, now_secs: u64) -> bool
pub fn is_expired(&self, now_secs: u64) -> bool
Returns true when now_secs has passed the entry’s deadline.
A TTL of 0 means the entry never expires.
Sourcepub fn remaining_secs(&self, now_secs: u64) -> u64
pub fn remaining_secs(&self, now_secs: u64) -> u64
Seconds remaining before expiry, saturating at zero once expired.
Returns u64::MAX for entries with TTL == 0 (no expiry).
Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for TtlEntry<V>where
V: Freeze,
impl<V> RefUnwindSafe for TtlEntry<V>where
V: RefUnwindSafe,
impl<V> Send for TtlEntry<V>where
V: Send,
impl<V> Sync for TtlEntry<V>where
V: Sync,
impl<V> Unpin for TtlEntry<V>where
V: Unpin,
impl<V> UnsafeUnpin for TtlEntry<V>where
V: UnsafeUnpin,
impl<V> UnwindSafe for TtlEntry<V>where
V: UnwindSafe,
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
Mutably borrows from an owned value. Read more