CacheBuilder

Struct CacheBuilder 

Source
pub struct CacheBuilder<K, V, S>
where K: Key, V: Value, S: HashBuilder,
{ /* private fields */ }
Expand description

In-memory cache builder.

Implementations§

Source§

impl<K, V> CacheBuilder<K, V, DefaultHasher>
where K: Key, V: Value,

Source

pub fn new(capacity: usize) -> Self

Create a new in-memory cache builder.

Source§

impl<K, V, S> CacheBuilder<K, V, S>
where K: Key, V: Value, S: HashBuilder,

Source

pub fn with_name(self, name: impl Into<Cow<'static, str>>) -> Self

Set the name of the foyer in-memory cache instance.

foyer will use the name as the prefix of the metric names.

Default: foyer.

Source

pub fn with_shards(self, shards: usize) -> Self

Set in-memory cache sharding count. Entries will be distributed to different shards based on their hash. Operations on different shard can be parallelized.

Source

pub fn with_eviction_config( self, eviction_config: impl Into<EvictionConfig>, ) -> Self

Set in-memory cache eviction algorithm.

The default value is a general-used w-TinyLFU algorithm.

Source

pub fn with_hash_builder<OS>(self, hash_builder: OS) -> CacheBuilder<K, V, OS>
where OS: HashBuilder,

Set in-memory cache hash builder.

Source

pub fn with_weighter(self, weighter: impl Weighter<K, V>) -> Self

Set in-memory cache weighter.

Source

pub fn with_filter(self, filter: impl Filter<K, V>) -> Self

Set the filter for the in-memory cache.

The filter is used to decide whether to admit or reject an entry based on its key and value.

If the filter returns true, the key value can be inserted into the in-memory cache; otherwise, the key value cannot be inserted.

To ensure API consistency, the in-memory cache will still return a cache entry, but it will not count towards the in-memory cache usage, and it will be immediately reclaimed when the cache entry is dropped.

Source

pub fn with_event_listener( self, event_listener: Arc<dyn EventListener<Key = K, Value = V>>, ) -> Self

Set event listener.

Source

pub fn with_metrics_registry( self, registry: BoxedRegistry, ) -> CacheBuilder<K, V, S>

Set metrics registry.

Default: NoopMetricsRegistry.

Source

pub fn build<P>(self) -> Cache<K, V, S, P>
where P: Properties,

Build in-memory cache with the given configuration.

Auto Trait Implementations§

§

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

§

impl<K, V, S> !RefUnwindSafe for CacheBuilder<K, V, S>

§

impl<K, V, S> Send for CacheBuilder<K, V, S>

§

impl<K, V, S> Sync for CacheBuilder<K, V, S>

§

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

§

impl<K, V, S> !UnwindSafe for CacheBuilder<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Scope for T

Source§

fn with<F, R>(self, f: F) -> R
where Self: Sized, F: FnOnce(Self) -> R,

Scoped with ownership.
Source§

fn with_ref<F, R>(&self, f: F) -> R
where F: FnOnce(&Self) -> R,

Scoped with reference.
Source§

fn with_mut<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut Self) -> R,

Scoped with mutable reference.
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> Value for T
where T: Send + Sync + 'static,