pub struct LruCacheWithTtl<K: Clone + Debug + Hash + Eq, V: Clone + Debug + Send + Sync> { /* private fields */ }Implementations§
Source§impl<K: Clone + Debug + Hash + Eq + Send + Sync + Debug + 'static, V: Clone + Debug + Send + Sync + 'static> LruCacheWithTtl<K, V>
impl<K: Clone + Debug + Hash + Eq + Send + Sync + Debug + 'static, V: Clone + Debug + Send + Sync + 'static> LruCacheWithTtl<K, V>
pub fn new<S: Into<String>>(name: S, capacity: usize) -> Self
pub fn set_allow_stale_reads(&self, value: bool)
pub fn set_sema_timeout(&self, duration: Duration)
pub fn get_sema_timeout(&self) -> Duration
pub fn clear(&self) -> usize
pub fn lookup<Q>(&self, name: &Q) -> Option<ItemLookup<V>>
pub fn get<Q>(&self, name: &Q) -> Option<V>
pub async fn insert(&self, name: K, item: V, expiration: Instant) -> V
Sourcepub async fn get_or_try_insert<E: Into<Error>, TTL: FnOnce(&V) -> Duration>(
&self,
name: &K,
ttl_func: TTL,
fut: impl Future<Output = Result<V, E>>,
) -> Result<ItemLookup<V>, Arc<Error>>
pub async fn get_or_try_insert<E: Into<Error>, TTL: FnOnce(&V) -> Duration>( &self, name: &K, ttl_func: TTL, fut: impl Future<Output = Result<V, E>>, ) -> Result<ItemLookup<V>, Arc<Error>>
Returns the cached item for name, or runs fut to produce one and
insert it, then returns it. ttl_func computes the TTL to store the
result under from the produced value, or a caller that wants a fixed TTL
can ignore its argument and return a constant.
Concurrent calls for the same name run fut at most once: all of
them receive its outcome, success or failure.
Sourcepub async fn get_or_try_insert_detached<E, TTL, MK, F>(
&self,
name: &K,
ttl_func: TTL,
make_fut: MK,
populate_timeout: Duration,
) -> Result<ItemLookup<V>, Arc<Error>>
pub async fn get_or_try_insert_detached<E, TTL, MK, F>( &self, name: &K, ttl_func: TTL, make_fut: MK, populate_timeout: Duration, ) -> Result<ItemLookup<V>, Arc<Error>>
Get an existing item, or populate and insert one. If this call is cancelled while the entry is being populated, the populate keeps running on its own task and the entry still ends up populated.
This call reports is_fresh as false.
make_fut and ttl_func (which must be Clone) may each be invoked
more than once, to retry the populate after populate_timeout elapses.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for LruCacheWithTtl<K, V>
impl<K, V> !RefUnwindSafe for LruCacheWithTtl<K, V>
impl<K, V> Send for LruCacheWithTtl<K, V>
impl<K, V> Sync for LruCacheWithTtl<K, V>
impl<K, V> Unpin for LruCacheWithTtl<K, V>
impl<K, V> !UnwindSafe for LruCacheWithTtl<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