Struct AsyncLruCacheInner

Source
struct AsyncLruCacheInner<Key: Clone + Copy + Debug + PartialEq + Eq + Hash + Send + Sync, Value: Send + Sync, IoBackend: AsyncLruCacheBackend<Key = Key, Value = Value>> {
    backend: IoBackend,
    map: RwLock<HashMap<Key, AsyncLruCacheEntry<Value>>>,
    flush_before: Mutex<Vec<Arc<dyn FlushableCache>>>,
    lru_timer: AtomicUsize,
    limit: usize,
}
Expand description

Least-recently-used cache with async access.

Fields§

§backend: IoBackend

I/O back-end that performs loading and flushing of cache entries.

§map: RwLock<HashMap<Key, AsyncLruCacheEntry<Value>>>

Cache entries.

§flush_before: Mutex<Vec<Arc<dyn FlushableCache>>>

Flush dependencies (flush these first).

§lru_timer: AtomicUsize

Monotonically increasing counter to generate “timestamps”.

§limit: usize

Upper limit of how many entries to cache.

Implementations§

Source§

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

Source

async fn flush_dependencies( flush_before: &mut MutexGuard<'_, Vec<Arc<dyn FlushableCache>>>, ) -> Result<()>

Flush all dependencies.

Flush all caches that must be flushed before this one. Remove all successfully flushed caches from our dependency list.

Call with a guard that should be dropped only after this cache is flushed, so that no new dependencies can enter while we are still flushing this cache.

Source

async fn ensure_free_entry( &self, map: &mut RwLockWriteGuard<'_, HashMap<K, AsyncLruCacheEntry<V>>>, ) -> Result<()>

Ensure there is at least one free entry in the cache.

Do this by evicting (flushing) existing entries, if necessary.

Source

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

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

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

Flush all cache entries.

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

Source

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.

Trait Implementations§

Source§

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

Source§

fn flush<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Flush the cache.
Source§

fn check_circular<'life0, 'life1, 'async_trait>( &'life0 self, other: &'life1 Arc<dyn FlushableCache>, ) -> Pin<Box<dyn Future<Output = bool> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check of circular dependencies. Read more

Auto Trait Implementations§

§

impl<Key, Value, IoBackend> !Freeze for AsyncLruCacheInner<Key, Value, IoBackend>

§

impl<Key, Value, IoBackend> !RefUnwindSafe for AsyncLruCacheInner<Key, Value, IoBackend>

§

impl<Key, Value, IoBackend> Send for AsyncLruCacheInner<Key, Value, IoBackend>

§

impl<Key, Value, IoBackend> Sync for AsyncLruCacheInner<Key, Value, IoBackend>

§

impl<Key, Value, IoBackend> Unpin for AsyncLruCacheInner<Key, Value, IoBackend>
where IoBackend: Unpin, Key: Unpin,

§

impl<Key, Value, IoBackend> !UnwindSafe for AsyncLruCacheInner<Key, Value, IoBackend>

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