pub struct ShardedCache { /* private fields */ }Expand description
A concurrent cache backed by N power-of-two LRU shards.
Keys are routed to shards via hash(key) & (n_shards - 1). Each shard
is independently protected by a Mutex<LruCache<Vec<u8>, Vec<u8>>>.
§Panics
new panics if n_shards is not a power of two, or if n_shards is 0.
Implementations§
Source§impl ShardedCache
impl ShardedCache
Sourcepub fn new(n_shards: usize, shard_cap: usize) -> Self
pub fn new(n_shards: usize, shard_cap: usize) -> Self
Create a new sharded cache.
n_shards: number of shards — must be a power of two.shard_cap: capacity per shard (entry count).
§Panics
Panics if n_shards == 0 or !n_shards.is_power_of_two().
Sourcepub fn get(&self, key: &[u8]) -> Option<Vec<u8>>
pub fn get(&self, key: &[u8]) -> Option<Vec<u8>>
Look up key, returning a cloned copy of the value if present.
Returns None if the key is absent or expired.
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