tiered_cache

Struct AutoCache

Source
pub struct AutoCache<K, V>
where K: Hash + Eq + Clone + Send + Sync + HeapSize + 'static, V: Clone + Send + Sync + HeapSize + 'static,
{ /* private fields */ }
Expand description

High-performance multi-tiered cache with automatic sizing

Implementations§

Source§

impl<K, V> AutoCache<K, V>
where K: Hash + Eq + Clone + Send + Sync + HeapSize + 'static, V: Clone + Send + Sync + HeapSize + 'static,

Source

pub fn new(config: CacheConfig) -> Self

Creates a new cache

Source

pub async fn get_or_update<F, Fut>(&self, key: K, updater: F) -> Option<Arc<V>>
where F: FnOnce() -> Fut, Fut: Future<Output = Option<V>>,

Gets or updates a cache entry asynchronously

Source

pub fn put(&self, key: K, value: V) -> Option<V>

Puts a value into the cache

Source

pub fn get(&self, key: &K) -> Option<Arc<V>>

Gets a value from the cache

Source

pub fn subscribe_updates(&self) -> Receiver<K>

Subscribes to cache updates

Source

pub fn stats(&self) -> CacheStats

Gets cache statistics

Source

pub fn remove(&self, key: &K) -> Option<V>

Removes a value from the cache

Source

pub fn clear(&self)

Clears the cache

Auto Trait Implementations§

§

impl<K, V> Freeze for AutoCache<K, V>

§

impl<K, V> !RefUnwindSafe for AutoCache<K, V>

§

impl<K, V> Send for AutoCache<K, V>

§

impl<K, V> Sync for AutoCache<K, V>

§

impl<K, V> Unpin for AutoCache<K, V>

§

impl<K, V> !UnwindSafe for AutoCache<K, V>

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.

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.
Source§

impl<T> ValueSize for T

Source§

fn value_size(&self) -> usize

The size of this value in bytes, excluding allocated data. Read more
Source§

fn value_size_sum_iter<'item>(iterator: impl Iterator<Item = &'item T>) -> usize
where T: 'item,

The total sum of the sizes of all values in the given iterator, in bytes. This is default-implemented by computing ValueSize::value_size on every element and summing them. For Sized types, a more potentially efficient implementation using Iterator::count is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more
Source§

fn value_size_sum_exact_size_iter<'item>( iterator: impl ExactSizeIterator<Item = &'item T>, ) -> usize
where T: 'item,

The total sum of the sizes of all values in the given exact-size-iterator, in bytes. This is default-implemented by using ValueSize::value_size_sum_iter. For Sized types, a usually more efficient implementation using ExactSizeIterator::len is provided. If you are implementing this trait manually, it is unlikely to be more efficient to provide a manual implementation here. Read more