pub struct MessageCache { /* private fields */ }Expand description
Thread-safe message cache with TTL-based eviction.
Messages are stored for a configurable duration to serve Graft requests from nodes that missed the initial broadcast.
Implementations§
Source§impl MessageCache
impl MessageCache
Sourcepub fn new(ttl: Duration, max_size: usize) -> Self
pub fn new(ttl: Duration, max_size: usize) -> Self
Create a new message cache with the specified TTL and max size.
Sourcepub fn insert(&self, id: MessageId, payload: Bytes)
pub fn insert(&self, id: MessageId, payload: Bytes)
Insert a message into the cache.
If the message already exists, this is a no-op. If the cache is full, oldest entries are evicted.
Sourcepub fn get(&self, id: &MessageId) -> Option<Arc<Bytes>>
pub fn get(&self, id: &MessageId) -> Option<Arc<Bytes>>
Get a message from the cache.
Returns None if the message is not in the cache or has expired.
Returns a cloned Arc to avoid holding locks during message sending.
Sourcepub fn contains(&self, id: &MessageId) -> bool
pub fn contains(&self, id: &MessageId) -> bool
Check if a message exists in the cache (without returning it).
Sourcepub fn get_many(&self, ids: &[MessageId]) -> HashMap<MessageId, Arc<Bytes>>
pub fn get_many(&self, ids: &[MessageId]) -> HashMap<MessageId, Arc<Bytes>>
Get multiple messages from the cache.
Returns a map of found message IDs to their payloads.
Sourcepub fn evict_expired(&self)
pub fn evict_expired(&self)
Remove all expired entries from the cache.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
Get cache statistics.
Trait Implementations§
Source§impl Debug for MessageCache
impl Debug for MessageCache
Auto Trait Implementations§
impl !Freeze for MessageCache
impl !RefUnwindSafe for MessageCache
impl Send for MessageCache
impl Sync for MessageCache
impl Unpin for MessageCache
impl UnwindSafe for MessageCache
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
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> ⓘ
Converts
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> ⓘ
Converts
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 more