pub struct Cache<K, V, M = (), B = MemoryBackend<K, V, M>>where
K: Hash + Eq + Clone + Send + Sync + 'static,
V: Clone + Send + Sync + 'static,
M: EntryMetadata + Default,
B: StorageBackend<Key = K, Value = V, Metadata = M>,{ /* private fields */ }Expand description
Main cache implementation
Implementations§
Source§impl<K, V, M, B> Cache<K, V, M, B>where
K: Hash + Eq + Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
V: Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
M: EntryMetadata + Default,
B: StorageBackend<Key = K, Value = V, Metadata = M>,
impl<K, V, M, B> Cache<K, V, M, B>where
K: Hash + Eq + Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
V: Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
M: EntryMetadata + Default,
B: StorageBackend<Key = K, Value = V, Metadata = M>,
Sourcepub async fn new(config: CacheConfig, backend: B) -> Result<Self>
pub async fn new(config: CacheConfig, backend: B) -> Result<Self>
Create a new cache with the given configuration and backend
Sourcepub async fn with_config(config: CacheConfig) -> Result<Self>where
B: Default,
pub async fn with_config(config: CacheConfig) -> Result<Self>where
B: Default,
Create a new cache with default memory backend
Sourcepub async fn add_entry(&self, entry: CacheEntry<K, V, M>) -> Result<()>
pub async fn add_entry(&self, entry: CacheEntry<K, V, M>) -> Result<()>
Add an entry to the cache
Sourcepub async fn get_entries(&self, key: &K) -> Option<Vec<CacheEntry<K, V, M>>>
pub async fn get_entries(&self, key: &K) -> Option<Vec<CacheEntry<K, V, M>>>
Get all entries for a key
Sourcepub async fn get_latest(&self, key: &K) -> Option<CacheEntry<K, V, M>>
pub async fn get_latest(&self, key: &K) -> Option<CacheEntry<K, V, M>>
Get the latest entry for a key
Sourcepub async fn search<Q>(&self, query: &Q) -> Vec<CacheEntry<K, V, M>>where
CacheEntry<K, V, M>: Searchable<Query = Q>,
pub async fn search<Q>(&self, query: &Q) -> Vec<CacheEntry<K, V, M>>where
CacheEntry<K, V, M>: Searchable<Query = Q>,
Search entries based on a query
Sourcepub async fn get_stats(&self) -> CacheStats
pub async fn get_stats(&self) -> CacheStats
Get cache statistics
Trait Implementations§
Source§impl<K, V, M, B> AsyncCache<K, V> for Cache<K, V, M, B>where
K: Hash + Eq + Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
V: Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
M: EntryMetadata + Default,
B: StorageBackend<Key = K, Value = V, Metadata = M>,
impl<K, V, M, B> AsyncCache<K, V> for Cache<K, V, M, B>where
K: Hash + Eq + Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
V: Clone + Send + Sync + Serialize + DeserializeOwned + 'static,
M: EntryMetadata + Default,
B: StorageBackend<Key = K, Value = V, Metadata = M>,
Source§type Error = CacheError
type Error = CacheError
Error type for cache operations
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get a value from the cache
Source§fn put<'life0, 'async_trait>(
&'life0 self,
key: K,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn put<'life0, 'async_trait>(
&'life0 self,
key: K,
value: V,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Put a value into the cache
Source§fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<Option<V>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Remove a value from the cache
Source§fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Clear all entries from the cache
Source§fn contains<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn contains<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 K,
) -> Pin<Box<dyn Future<Output = Result<bool, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Check if the cache contains a key
Auto Trait Implementations§
impl<K, V, M, B> Freeze for Cache<K, V, M, B>
impl<K, V, M = (), B = MemoryBackend<K, V, M>> !RefUnwindSafe for Cache<K, V, M, B>
impl<K, V, M, B> Send for Cache<K, V, M, B>
impl<K, V, M, B> Sync for Cache<K, V, M, B>
impl<K, V, M, B> Unpin for Cache<K, V, M, B>
impl<K, V, M, B> UnsafeUnpin for Cache<K, V, M, B>
impl<K, V, M = (), B = MemoryBackend<K, V, M>> !UnwindSafe for Cache<K, V, M, B>
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