Struct freqache::LFUCache[][src]

pub struct LFUCache<K, V, F> { /* fields omitted */ }

A weighted, thread-safe, futures-aware least-frequently-used cache

Implementations

impl<K: Clone + Eq + Hash, V: Entry, F: Fn()> LFUCache<K, V, F>[src]

pub fn new(capacity: u64, policy: F) -> Self[src]

Construct a new LFUCache.

pub fn contains_key<Q: ?Sized>(&mut self, key: &Q) -> bool where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Return true if the cache contains the given key.

pub async fn get<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Clone and return the value of the cache entry with the given key.

pub async fn insert(&mut self, key: K, value: V) -> bool[src]

Add a new entry to the cache.

pub fn is_full(&self) -> bool[src]

Return true if the cache is full.

pub fn len(&self) -> usize[src]

Return the number of entries in this cache.

pub async fn remove<Q>(&mut self, key: &Q) -> bool where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Remove an entry from the cache, and return true if it was present.

pub async fn traverse<C: FnMut(&V) + Send>(&self, f: C)[src]

Traverse the cache values beginning with the least-frequent.

pub async fn evict<E, Fut: Future<Output = Result<bool, E>>, C: Fn(&K, &V) -> Fut + Send>(
    &mut self,
    f: C
) -> Result<(), E>
[src]

Traverse the cache values beginning with the least-frequent, and evict the values from the cache when the given callback returns Ok(true), until is_full returns false.

Auto Trait Implementations

impl<K, V, F> RefUnwindSafe for LFUCache<K, V, F> where
    F: RefUnwindSafe,
    K: RefUnwindSafe

impl<K, V, F> Send for LFUCache<K, V, F> where
    F: Send,
    K: Send,
    V: Send

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

impl<K, V, F> Unpin for LFUCache<K, V, F> where
    F: Unpin,
    K: Unpin

impl<K, V, F> UnwindSafe for LFUCache<K, V, F> where
    F: UnwindSafe,
    K: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.