Skip to main content

S3FifoCache

Struct S3FifoCache 

Source
pub struct S3FifoCache<K, V, S = RandomState> { /* private fields */ }
Expand description

A sharded, weighted, thread-safe S3-FIFO cache backed directly by quick_cache.

Implementations§

Source§

impl<K, V, S> S3FifoCache<K, V, S>

Source

pub const DEFAULT_SHARDS: usize = 256

Default power-of-two shard count used by S3FifoCache::new.

Source§

impl<K, V> S3FifoCache<K, V, RandomState>
where K: Eq + Hash + Clone, V: CacheEntry + Clone,

Source

pub fn new(total_capacity_bytes: usize) -> Self

Creates a cache with Self::DEFAULT_SHARDS shards.

Source

pub fn with_shards(total_capacity_bytes: usize, num_shards: usize) -> Self

Creates a cache with an explicit shard count.

§Panics

Panics if num_shards == 0 or if num_shards is not a power of two.

Source§

impl<K, V, S> S3FifoCache<K, V, S>
where K: Eq + Hash + Clone, V: CacheEntry + Clone, S: BuildHasher + Clone,

Source

pub fn with_hasher( total_capacity_bytes: usize, num_shards: usize, hash_builder: S, ) -> Self

Creates a cache with an explicit shard count and hash builder.

Because quick_cache uses equal-capacity shards internally, the actual backend capacity may round up when total_capacity_bytes is not evenly divisible by num_shards.

§Panics

Panics if num_shards == 0 or if num_shards is not a power of two.

Source

pub fn insert(&self, key: K, value: V)

Inserts or replaces key with value.

Source

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

Looks up key and returns a clone of the stored value.

Source

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

Removes key if present and returns the removed value.

Source

pub fn remove_if<F>(&self, predicate: F)
where F: Fn(&K) -> bool,

Removes all entries matching predicate and returns the number removed.

Source

pub fn contains_key(&self, key: &K) -> bool

Returns true if key is currently present.

Source

pub fn len(&self) -> usize

Returns the current number of live entries.

Source

pub fn total_charge(&self) -> usize

Returns the current total weighted charge.

Source

pub fn total_capacity(&self) -> usize

Returns the backend’s configured total weighted capacity.

This may be larger than the requested constructor argument when the requested total capacity is not evenly divisible across shards.

Source

pub fn shard_count(&self) -> usize

Returns the number of backend shards.

Trait Implementations§

Source§

impl<K, V, S> BufferCache<K, V> for S3FifoCache<K, V, S>
where K: Eq + Hash + Clone + Send + Sync + 'static, V: CacheEntry + Clone + Send + Sync + 'static, S: BuildHasher + Clone + Send + Sync + 'static,

Source§

fn as_any(&self) -> &dyn Any

Returns this backend as Any for backend-specific downcasts.
Source§

fn strategy(&self) -> BufferCacheStrategy

Returns the eviction strategy used by this cache.
Source§

fn insert(&self, key: K, value: V)

Inserts or replaces key with value. Read more
Source§

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

Looks up key and returns a clone of the stored value.
Source§

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

Removes key if it is present and returns the removed value.
Source§

fn remove_if(&self, predicate: &dyn Fn(&K) -> bool)

Removes every entry whose key matches predicate.
Source§

fn contains_key(&self, key: &K) -> bool

Returns true if key is currently resident.
Source§

fn len(&self) -> usize

Returns the number of resident entries.
Source§

fn total_charge(&self) -> usize

Returns the total resident weight.
Source§

fn total_capacity(&self) -> usize

Returns the configured total weight capacity.
Source§

fn shard_count(&self) -> usize

Returns the number of shards used by this backend.
Source§

fn is_empty(&self) -> bool

Returns true if the cache has no resident entries.

Auto Trait Implementations§

§

impl<K, V, S> Freeze for S3FifoCache<K, V, S>
where S: Freeze,

§

impl<K, V, S = RandomState> !RefUnwindSafe for S3FifoCache<K, V, S>

§

impl<K, V, S> Send for S3FifoCache<K, V, S>
where S: Send, K: Send, V: Send + Sync,

§

impl<K, V, S> Sync for S3FifoCache<K, V, S>
where S: Sync + Send, K: Sync + Send, V: Sync + Send,

§

impl<K, V, S> Unpin for S3FifoCache<K, V, S>
where S: Unpin, K: Unpin, V: Unpin,

§

impl<K, V, S> UnsafeUnpin for S3FifoCache<K, V, S>
where S: UnsafeUnpin,

§

impl<K, V, S = RandomState> !UnwindSafe for S3FifoCache<K, V, S>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more