Skip to main content

SharedCacheConfigBuilder

Struct SharedCacheConfigBuilder 

Source
pub struct SharedCacheConfigBuilder<Req, K, Resp> { /* private fields */ }
Expand description

Builder for configuring and constructing a shared cache layer.

Implementations§

Source§

impl<Req, K, Resp> SharedCacheConfigBuilder<Req, K, Resp>
where K: Hash + Eq + Clone + Send + 'static, Resp: Clone + Send + 'static,

Source

pub fn new() -> Self

Creates a new builder with default values.

Source

pub fn max_size(self, size: usize) -> Self

Sets the maximum number of entries in the cache.

Default: 100

Source

pub fn ttl(self, ttl: Duration) -> Self

Sets the time-to-live for cached entries.

If set, entries will expire after the specified duration. Default: None (no expiration)

Source

pub fn eviction_policy(self, policy: EvictionPolicy) -> Self

Sets the eviction policy for the cache.

Determines which entry to evict when the cache reaches capacity.

§Options
  • EvictionPolicy::Lru - Least Recently Used (default)
  • EvictionPolicy::Lfu - Least Frequently Used
  • EvictionPolicy::Fifo - First In, First Out

Default: EvictionPolicy::Lru

Source

pub fn key_extractor<F>(self, f: F) -> Self
where F: Fn(&Req) -> K + Send + Sync + 'static,

Sets the function that extracts a cache key from a request.

This function must be provided before building.

Source

pub fn name(self, name: impl Into<String>) -> Self

Sets the name of this cache instance for observability.

Default: "<unnamed>"

Source

pub fn on_hit<F>(self, f: F) -> Self
where F: Fn() + Send + Sync + 'static,

Registers a callback when a cache hit occurs.

Source

pub fn on_miss<F>(self, f: F) -> Self
where F: Fn() + Send + Sync + 'static,

Registers a callback when a cache miss occurs.

Source

pub fn on_eviction<F>(self, f: F) -> Self
where F: Fn() + Send + Sync + 'static,

Registers a callback when an entry is evicted from the cache.

Source

pub fn build(self) -> SharedCacheLayer<Req, K, Resp>

Builds the shared cache layer.

§Panics

Panics if key_extractor was not set.

Trait Implementations§

Source§

impl<Req, K, Resp> Default for SharedCacheConfigBuilder<Req, K, Resp>
where K: Hash + Eq + Clone + Send + 'static, Resp: Clone + Send + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Req, K, Resp> Freeze for SharedCacheConfigBuilder<Req, K, Resp>

§

impl<Req, K, Resp> !RefUnwindSafe for SharedCacheConfigBuilder<Req, K, Resp>

§

impl<Req, K, Resp> Send for SharedCacheConfigBuilder<Req, K, Resp>
where Resp: Send,

§

impl<Req, K, Resp> Sync for SharedCacheConfigBuilder<Req, K, Resp>
where Resp: Sync,

§

impl<Req, K, Resp> Unpin for SharedCacheConfigBuilder<Req, K, Resp>
where Resp: Unpin,

§

impl<Req, K, Resp> UnsafeUnpin for SharedCacheConfigBuilder<Req, K, Resp>

§

impl<Req, K, Resp> !UnwindSafe for SharedCacheConfigBuilder<Req, K, Resp>

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.