Struct concurrent_lru::unsharded::LruCache[][src]

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

A concurrent LRU cache.

A value is pinned while its CacheHandle is live, and thus cannot be evicted. Capacity specifies how many values could be cached, including pinned and unpinned. Eviction happens when #value > capacity, or Lru::prune is called.

Keys should be lightweight, while values could be heavyweight. That is, creating (Lru::get_or_init) and dropping value could be time-consuming, and the cache itself would not be blocked.

Implementations

impl<K, V> LruCache<K, V> where
    K: Send + Sync + Hash + Eq + Clone,
    V: Send + Sync
[src]

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

impl<K, V> LruCache<K, V> where
    K: Hash + Eq + Clone
[src]

pub fn advice_evict(&self, key: K)[src]

Evict a value if it is present and unpinned.

pub fn prune(&self)[src]

Prune all unpinned values.

pub fn total_charge(&self) -> u64[src]

pub fn get(&self, key: K) -> Option<CacheHandle<'_, K, V>>[src]

Get the cache handle for the key, return None if not present. The value is pinned in cache while the cache handle is live.

pub fn get_or_try_init<E>(
    &self,
    key: K,
    charge: u64,
    init: impl FnOnce(&K) -> Result<V, E>
) -> Result<CacheHandle<'_, K, V>, E>
[src]

Error handling version of get_or_init. Value is not inserted if error occurs.

pub fn get_or_init(
    &self,
    key: K,
    charge: u64,
    init: impl FnOnce(&K) -> V
) -> CacheHandle<'_, K, V>
[src]

Get the cache handle for the key, initialize the value if not present. The value is pinned in cache while the cache handle is live.

Multiple threads calling get_or_init on the same key is fine. The value would be constructed exactly once.

Trait Implementations

impl<K, V> Debug for LruCache<K, V> where
    K: Debug,
    V: Debug
[src]

impl<K, V> Send for LruCache<K, V>[src]

impl<K, V> Sync for LruCache<K, V>[src]

Auto Trait Implementations

impl<K, V> RefUnwindSafe for LruCache<K, V>[src]

impl<K, V> Unpin for LruCache<K, V> where
    K: Unpin
[src]

impl<K, V> UnwindSafe for LruCache<K, V>[src]

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.