Struct AsyncLruCache

Source
pub(crate) struct AsyncLruCache<K: Clone + Copy + Debug + PartialEq + Eq + Hash + Send + Sync, V: Send + Sync, B: AsyncLruCacheBackend<Key = K, Value = V>>(Arc<AsyncLruCacheInner<K, V, B>>);
Expand description

Least-recently-used cache with async access.

Keeps the least recently used entries up to a limited count. Accessing and flushing is async-aware.

K is the key used to uniquely identify cache entries, V is the cached data.

Tuple Fields§

§0: Arc<AsyncLruCacheInner<K, V, B>>

Implementations§

Source§

impl<K: Clone + Copy + Debug + PartialEq + Eq + Hash + Send + Sync, V: Send + Sync, B: AsyncLruCacheBackend<Key = K, Value = V>> AsyncLruCache<K, V, B>

Source

pub fn new(backend: B, size: usize) -> Self

Create a new cache.

size is the maximum number of entries to keep in the cache.

Source

pub async fn get_or_insert(&self, key: K) -> Result<Arc<V>>

Retrieve an entry from the cache.

If there is no entry yet, run read() to generate it. If then there are more entries in the cache than its limit, flush out the oldest entry via flush().

Source

pub async fn insert(&self, key: K, value: Arc<V>) -> Result<()>

Force-insert the given object into the cache.

If there is an existing object under that key, it is flushed first.

Source

pub async fn flush(&self) -> Result<()>

Flush all cache entries.

Those entries are not evicted, but remain in the cache.

Source

pub async unsafe fn invalidate(&self) -> Result<()>

Evict all cache entries.

Evicts all cache entries without flushing them.

§Safety

Depending on the nature of the cache, this operation may be unsafe. Perform at your own risk.

Source§

impl<K: Clone + Copy + Debug + PartialEq + Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static, B: AsyncLruCacheBackend<Key = K, Value = V> + 'static> AsyncLruCache<K, V, B>

Source

pub async fn depend_on<K2: Clone + Copy + Debug + PartialEq + Eq + Hash + Send + Sync + 'static, V2: Send + Sync + 'static, B2: AsyncLruCacheBackend<Key = K2, Value = V2> + 'static>( &self, other: &AsyncLruCache<K2, V2, B2>, ) -> Result<()>

Set up a flush dependency.

Ensure that before anything in this cache is flushed, flush_before is flushed first.

Auto Trait Implementations§

§

impl<K, V, B> Freeze for AsyncLruCache<K, V, B>

§

impl<K, V, B> !RefUnwindSafe for AsyncLruCache<K, V, B>

§

impl<K, V, B> Send for AsyncLruCache<K, V, B>

§

impl<K, V, B> Sync for AsyncLruCache<K, V, B>

§

impl<K, V, B> Unpin for AsyncLruCache<K, V, B>

§

impl<K, V, B> !UnwindSafe for AsyncLruCache<K, V, B>

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