Struct concurrent_lru::unsharded::LruCache [−][src]
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]
K: Send + Sync + Hash + Eq + Clone,
V: Send + Sync,
impl<K, V> LruCache<K, V> where
K: Hash + Eq + Clone,
[src]
K: Hash + Eq + Clone,
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]
&self,
key: K,
charge: u64,
init: impl FnOnce(&K) -> Result<V, E>
) -> Result<CacheHandle<'_, K, V>, E>
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]
&self,
key: K,
charge: u64,
init: impl FnOnce(&K) -> V
) -> CacheHandle<'_, K, V>
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]
K: Debug,
V: Debug,
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]
K: Unpin,
impl<K, V> UnwindSafe for LruCache<K, V>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,