pub struct ShardedCache { /* private fields */ }Expand description
A high-performance sharded cache using DashMap.
This cache implementation:
- Uses
DashMapfor lock-free concurrent reads - Automatically notifies watches on snapshot updates
- Tracks statistics for monitoring
§Thread Safety
All operations are thread-safe. The cache uses DashMap internally,
which provides fine-grained locking at the bucket level rather than
a global lock.
§Important
All DashMap references are dropped before any async operations
to prevent holding locks across await points.
Implementations§
Source§impl ShardedCache
impl ShardedCache
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new sharded cache with a specific initial capacity.
Sourcepub fn watches(&self) -> &WatchManager
pub fn watches(&self) -> &WatchManager
Get the watch manager for creating watches.
Sourcepub fn stats(&self) -> &CacheStats
pub fn stats(&self) -> &CacheStats
Get cache statistics.
Sourcepub fn create_watch(&self, node: NodeHash) -> Watch
pub fn create_watch(&self, node: NodeHash) -> Watch
Create a watch for a node.
The watch will receive updates when the snapshot for this node changes.
If a snapshot already exists, the caller should check with get_snapshot
first.
Sourcepub fn cancel_watch(&self, watch_id: WatchId)
pub fn cancel_watch(&self, watch_id: WatchId)
Cancel a watch.
Sourcepub fn has_snapshot(&self, node: NodeHash) -> bool
pub fn has_snapshot(&self, node: NodeHash) -> bool
Check if a snapshot exists for a node.
Trait Implementations§
Source§impl Cache for ShardedCache
impl Cache for ShardedCache
Source§fn set_snapshot(&self, node: NodeHash, snapshot: Snapshot)
fn set_snapshot(&self, node: NodeHash, snapshot: Snapshot)
Set a snapshot for a node. Read more
Source§fn clear_snapshot(&self, node: NodeHash)
fn clear_snapshot(&self, node: NodeHash)
Clear the snapshot for a node.
Source§fn snapshot_count(&self) -> usize
fn snapshot_count(&self) -> usize
Get the number of cached snapshots.
Source§impl Debug for ShardedCache
impl Debug for ShardedCache
Auto Trait Implementations§
impl !Freeze for ShardedCache
impl !RefUnwindSafe for ShardedCache
impl Send for ShardedCache
impl Sync for ShardedCache
impl Unpin for ShardedCache
impl UnsafeUnpin for ShardedCache
impl !UnwindSafe for ShardedCache
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request