pub struct Cache<K = String, V = String>{ /* private fields */ }Expand description
Concurrent key-value cache with named buckets.
Uses DashMap internally for lock-free concurrent reads. Create named buckets for different entity types (products, listings, etc.).
Both key and value types default to String, so Cache is a drop-in
replacement for the previous untyped cache. Use Cache<i32, MyStruct>,
Cache<String, Vec<u8>>, etc. for typed buckets.
Implementations§
Source§impl<K, V> Cache<K, V>
impl<K, V> Cache<K, V>
pub fn new() -> Self
Sourcepub fn with_buckets(names: &[&str]) -> Self
pub fn with_buckets(names: &[&str]) -> Self
Create a set of named buckets upfront.
Sourcepub fn set(&self, bucket: &str, key: K, value: V)
pub fn set(&self, bucket: &str, key: K, value: V)
Set a value in a named bucket (creates the bucket if it doesn’t exist).
Sourcepub fn clear_bucket(&self, bucket: &str)
pub fn clear_bucket(&self, bucket: &str)
Clear all entries in a specific bucket.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for Cache<K, V>
impl<K = String, V = String> !RefUnwindSafe for Cache<K, V>
impl<K, V> Send for Cache<K, V>
impl<K, V> Sync for Cache<K, V>
impl<K, V> Unpin for Cache<K, V>
impl<K, V> UnsafeUnpin for Cache<K, V>
impl<K = String, V = String> !UnwindSafe for Cache<K, V>
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