LruCacheWithTtl

Struct LruCacheWithTtl 

Source
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>

Source

pub fn new<S: Into<String>>(name: S, capacity: usize) -> Self

Source

pub fn set_allow_stale_reads(&self, value: bool)

Source

pub fn set_sema_timeout(&self, duration: Duration)

Source

pub fn get_sema_timeout(&self) -> Duration

Source

pub fn clear(&self) -> usize

Source

pub fn lookup<Q>(&self, name: &Q) -> Option<ItemLookup<V>>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

pub fn get<Q>(&self, name: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source

pub async fn insert(&self, name: K, item: V, expiration: Instant) -> V

Source

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.

Source

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>>
where E: Into<Error> + Send + 'static, TTL: Clone + Send + 'static + FnOnce(&V) -> Duration, MK: Fn() -> F, F: Future<Output = Result<V, E>> + Send + 'static,

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§

Source§

impl<K: Clone + Debug + Hash + Eq, V: Clone + Debug + Send + Sync> Clone for LruCacheWithTtl<K, V>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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>
where K: Send + Sync,

§

impl<K, V> Sync for LruCacheWithTtl<K, V>
where K: Send + Sync,

§

impl<K, V> Unpin for LruCacheWithTtl<K, V>

§

impl<K, V> !UnwindSafe for LruCacheWithTtl<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,