Skip to main content

CacheBuilder

Struct CacheBuilder 

Source
pub struct CacheBuilder<B, P, CM, O> { /* private fields */ }
Expand description

Builder for Cache with typestate pattern.

The builder ensures at compile time that both backend and policy are configured before the cache can be built.

Implementations§

Source§

impl<P, CM, O> CacheBuilder<NoBackend, P, CM, O>

Source

pub fn backend<B: CacheBackend>( self, backend: B, ) -> CacheBuilder<WithBackend<B>, P, CM, O>

Set the cache backend.

§Example
let builder = Cache::builder()
    .backend(MokaBackend::builder().build());
Source§

impl<B, CM, O> CacheBuilder<B, NoPolicy, CM, O>

Source

pub fn policy(self, policy: PolicyConfig) -> CacheBuilder<B, WithPolicy, CM, O>

Set the cache policy configuration.

§Example
let builder = Cache::builder()
    .policy(PolicyConfig::builder().ttl(Duration::from_secs(60)).build());
Source§

impl<B, P, CM, O> CacheBuilder<B, P, CM, O>

Source

pub fn concurrency_manager<CM2>(self, cm: CM2) -> CacheBuilder<B, P, CM2, O>

Set the concurrency manager for dogpile prevention.

By default, NoopConcurrencyManager is used which doesn’t prevent dogpile. Use BroadcastConcurrencyManager for production workloads.

§Example
use hitbox::concurrency::BroadcastConcurrencyManager;

let cache = Cache::builder()
    .backend(backend)
    .policy(policy)
    .concurrency_manager(BroadcastConcurrencyManager::new())
    .build();
Source

pub fn offload<O2>(self, offload: O2) -> CacheBuilder<B, P, CM, O2>

Set the offload manager for background task execution.

By default, DisabledOffload is used which disables background revalidation. Use OffloadManager to enable Stale-While-Revalidate pattern.

§Example
use hitbox::offload::OffloadManager;

let cache = Cache::builder()
    .backend(backend)
    .policy(policy)
    .offload(OffloadManager::with_defaults())
    .build();
Source§

impl<B, CM, O> CacheBuilder<WithBackend<B>, WithPolicy, CM, O>
where B: CacheBackend,

Source

pub fn build(self) -> Cache<B, CM, O>

Build the cache configuration.

This method is only available when both backend and policy are configured.

Auto Trait Implementations§

§

impl<B, P, CM, O> Freeze for CacheBuilder<B, P, CM, O>
where B: Freeze, P: Freeze, CM: Freeze, O: Freeze,

§

impl<B, P, CM, O> RefUnwindSafe for CacheBuilder<B, P, CM, O>

§

impl<B, P, CM, O> Send for CacheBuilder<B, P, CM, O>
where B: Send, P: Send, CM: Send, O: Send,

§

impl<B, P, CM, O> Sync for CacheBuilder<B, P, CM, O>
where B: Sync, P: Sync, CM: Sync, O: Sync,

§

impl<B, P, CM, O> Unpin for CacheBuilder<B, P, CM, O>
where B: Unpin, P: Unpin, CM: Unpin, O: Unpin,

§

impl<B, P, CM, O> UnsafeUnpin for CacheBuilder<B, P, CM, O>

§

impl<B, P, CM, O> UnwindSafe for CacheBuilder<B, P, CM, O>

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