Skip to main content

CacheBuilder

Struct CacheBuilder 

Source
pub struct CacheBuilder<V> { /* private fields */ }
Expand description

Builder for a Cache.

use amalgam::{Cache, EntryOptions};
use std::time::Duration;

let cache: Cache<String> = Cache::builder()
    .name("users")
    .key_prefix("u:")
    .default_options(EntryOptions::new(Duration::from_secs(60)))
    .build();

Implementations§

Source§

impl<V> CacheBuilder<V>

Source

pub fn new() -> Self

Creates a builder with default settings.

Source

pub fn instance_id(self, id: impl AsRef<str>) -> Self

Sets this instance’s id (used to ignore its own backplane messages). A random id is generated if not set.

Source

pub fn distributed(self, distributed: Arc<dyn DistributedCache>) -> Self

Attaches an L2 distributed cache backend. Pair with serializer.

Source

pub fn serializer(self, serializer: Arc<dyn DistributedSerializer<V>>) -> Self

Sets the serializer used for the L2 wire format (e.g. JsonSerializer).

Source

pub fn backplane(self, backplane: Arc<dyn Backplane>) -> Self

Attaches a backplane for multi-node L1 invalidation.

Note: when a backplane is configured, build spawns a listener task and so must be called from within a tokio runtime.

Source

pub fn name(self, name: impl AsRef<str>) -> Self

Sets the cache’s name (used in events/diagnostics).

Source

pub fn key_prefix(self, prefix: impl AsRef<str>) -> Self

Sets a prefix prepended to every key.

Source

pub fn default_options(self, options: EntryOptions) -> Self

Sets the default entry options merged into every operation that does not supply its own.

Source

pub fn clock(self, clock: Arc<dyn Clock>) -> Self

Injects a custom Clock (e.g. ManualClock in tests).

Source

pub fn max_capacity(self, capacity: u64) -> Self

Caps the number of entries held in L1 (None = unbounded).

Source

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

Sets the number of single-flight lock shards (rounded up to a power of two).

Source

pub fn remove_by_tag_behavior(self, behavior: RemoveByTagBehavior) -> Self

Sets what remove_by_tag does to matched entries.

Source

pub fn events_capacity(self, capacity: usize) -> Self

Sets the event channel’s buffer capacity.

Source

pub fn distributed_locker(self, locker: Arc<dyn DistributedLocker>) -> Self

Attaches a cross-node distributed locker (e.g. Redis-backed) for cluster-wide single-flight.

Source

pub fn plugin(self, plugin: Arc<dyn Plugin>) -> Self

Registers a Plugin to observe events and lifecycle.

Source

pub fn distributed_circuit_breaker(self, duration: Duration) -> Self

Opens the L2 circuit breaker for duration after an L2 failure (Duration::ZERO disables it — the default).

Source

pub fn backplane_circuit_breaker(self, duration: Duration) -> Self

Opens the backplane circuit breaker for duration after a backplane failure (Duration::ZERO disables it — the default).

Source

pub fn auto_recovery(self, config: RecoveryConfig) -> Self

Configures (or disables) auto-recovery of failed L2 / backplane operations.

Source

pub fn default_options_provider( self, provider: Arc<dyn DefaultEntryOptionsProvider>, ) -> Self

Sets a provider of dynamic, per-key default options (consulted when a call supplies no explicit options).

Source

pub fn ignore_incoming_backplane(self, ignore: bool) -> Self

Drops all incoming backplane notifications (dangerous; for testing).

Source

pub fn distributed_wire_version(self, version: impl AsRef<str>) -> Self

Sets the L2 wire-format version combined with distributed keys.

Source

pub fn distributed_key_modifier_mode(self, mode: KeyModifierMode) -> Self

Sets how the wire-format version is combined with the L2 key (prefix, suffix, or none).

Source

pub fn disable_tagging(self, disable: bool) -> Self

Disables tagging cache-wide (FusionCache DisableTagging).

When enabled, the per-read tag/clear-marker check is skipped entirely (a small read-path saving for caches that never tag), and remove_by_tag / remove_by_tags / clear are ignored and logged at warn (never silently) — the Rust-idiomatic counterpart of FusionCache throwing on tag use when tagging is disabled. Off by default.

Source

pub fn wait_for_initial_backplane_subscribe(self, wait: bool) -> Self

Whether to establish the backplane subscription before build returns (FusionCache WaitForInitialBackplaneSubscribe, default true).

In amalgam this is inherently satisfied: the listener calls backplane.subscribe() synchronously inside build, and the Redis backplane completes its SUBSCRIBE during connect() before being handed to the builder — so there is no startup window where the node serves while unsubscribed. The flag is retained for configuration parity and is queryable via Cache::wait_for_initial_backplane_subscribe.

Source§

impl<V: Clone + Send + Sync + 'static> CacheBuilder<V>

Source

pub fn build(self) -> Cache<V>

Builds the cache.

Trait Implementations§

Source§

impl<V> Default for CacheBuilder<V>

Source§

fn default() -> Self

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

Auto Trait Implementations§

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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