Struct deduplicate::Deduplicate
source · [−]Expand description
Query de-duplication with optional cache.
When trying to avoid multiple slow or expensive retrievals, use this.
Implementations
sourceimpl<K, V> Deduplicate<K, V>where
K: Clone + Send + Eq + Hash + 'static,
V: Clone + Send + 'static,
impl<K, V> Deduplicate<K, V>where
K: Clone + Send + Eq + Hash + 'static,
V: Clone + Send + 'static,
sourcepub async fn new(retriever: Arc<dyn Retriever<Key = K, Value = V>>) -> Self
pub async fn new(retriever: Arc<dyn Retriever<Key = K, Value = V>>) -> Self
Create a new deduplicator for the provided retriever with default cache capacity: 512.
sourcepub async fn with_capacity(
retriever: Arc<dyn Retriever<Key = K, Value = V>>,
capacity: usize
) -> Self
pub async fn with_capacity(
retriever: Arc<dyn Retriever<Key = K, Value = V>>,
capacity: usize
) -> Self
Create a new deduplicator for the provided retriever with specified cache capacity. Note: If capacity is 0, then caching is disabled.
sourcepub fn set_retriever(
&mut self,
retriever: Arc<dyn Retriever<Key = K, Value = V>>
)
pub fn set_retriever(
&mut self,
retriever: Arc<dyn Retriever<Key = K, Value = V>>
)
Update the retriever to use for future gets. This will also clear the internal cache.
sourcepub async fn get(&self, key: &K) -> Result<V, DeduplicateError>
pub async fn get(&self, key: &K) -> Result<V, DeduplicateError>
Use the retriever to get a value. If the key cannot be retrieved, then a
DeduplicateError::NotFound error is returned. Many concurrent accessors can
attempt to get the same key, but the retriever will only be used once. It is
possible that the retriever will panic. In which case any concurrent accessors
will get the error: DeduplicateError::Failed
sourcepub fn insert(&mut self, key: K, value: V) -> Result<(), DeduplicateError>
pub fn insert(&mut self, key: K, value: V) -> Result<(), DeduplicateError>
Insert an entry directly into the cache.