Struct deduplicate::Deduplicate
source · pub struct Deduplicate<G, K, V>where
G: Fn(K) -> DeduplicateFuture<V> + Clone,
K: Clone + Send + Eq + Hash,
V: Clone + Send,{ /* private fields */ }Expand description
Query de-duplication with optional cache.
When trying to avoid multiple slow or expensive gets, use this.
Implementations§
source§impl<G, K, V> Deduplicate<G, K, V>where
G: Fn(K) -> DeduplicateFuture<V> + Clone,
K: Clone + Send + Eq + Hash + 'static,
V: Clone + Send + 'static,
impl<G, K, V> Deduplicate<G, K, V>where
G: Fn(K) -> DeduplicateFuture<V> + Clone,
K: Clone + Send + Eq + Hash + 'static,
V: Clone + Send + 'static,
sourcepub fn new(delegate: G) -> Self
pub fn new(delegate: G) -> Self
Create a new deduplicator for the provided delegate with default cache capacity: 512.
sourcepub fn with_capacity(delegate: G, capacity: usize) -> Self
pub fn with_capacity(delegate: G, capacity: usize) -> Self
Create a new deduplicator for the provided delegate with specified cache capacity. Note: If capacity is 0, then caching is disabled.
sourcepub fn set_delegate(&mut self, delegate: G)
pub fn set_delegate(&mut self, delegate: G)
Update the delegate to use for future gets. This will also clear the internal cache.
sourcepub async fn get(&self, key: K) -> Result<Option<V>, DeduplicateError>
pub async fn get(&self, key: K) -> Result<Option<V>, DeduplicateError>
Use the delegate to get a value.
Many concurrent accessors can attempt to get the same key, but the underlying get will only
be called once. If the delegate panics or is cancelled, 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. If there is no cache , this
will fail with DeduplicateError::NoCache.
Trait Implementations§
source§impl<G, K, V> Clone for Deduplicate<G, K, V>where
G: Fn(K) -> DeduplicateFuture<V> + Clone + Clone,
K: Clone + Send + Eq + Hash + Clone,
V: Clone + Send + Clone,
impl<G, K, V> Clone for Deduplicate<G, K, V>where
G: Fn(K) -> DeduplicateFuture<V> + Clone + Clone,
K: Clone + Send + Eq + Hash + Clone,
V: Clone + Send + Clone,
source§fn clone(&self) -> Deduplicate<G, K, V>
fn clone(&self) -> Deduplicate<G, K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more