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>
impl<V> CacheBuilder<V>
Sourcepub fn instance_id(self, id: impl AsRef<str>) -> Self
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.
Sourcepub fn distributed(self, distributed: Arc<dyn DistributedCache>) -> Self
pub fn distributed(self, distributed: Arc<dyn DistributedCache>) -> Self
Attaches an L2 distributed cache backend. Pair with
serializer.
Sourcepub fn serializer(self, serializer: Arc<dyn DistributedSerializer<V>>) -> Self
pub fn serializer(self, serializer: Arc<dyn DistributedSerializer<V>>) -> Self
Sets the serializer used for the L2 wire format (e.g.
JsonSerializer).
Sourcepub fn backplane(self, backplane: Arc<dyn Backplane>) -> Self
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.
Sourcepub fn name(self, name: impl AsRef<str>) -> Self
pub fn name(self, name: impl AsRef<str>) -> Self
Sets the cache’s name (used in events/diagnostics).
Sourcepub fn key_prefix(self, prefix: impl AsRef<str>) -> Self
pub fn key_prefix(self, prefix: impl AsRef<str>) -> Self
Sets a prefix prepended to every key.
Sourcepub fn default_options(self, options: EntryOptions) -> Self
pub fn default_options(self, options: EntryOptions) -> Self
Sets the default entry options merged into every operation that does not supply its own.
Sourcepub fn clock(self, clock: Arc<dyn Clock>) -> Self
pub fn clock(self, clock: Arc<dyn Clock>) -> Self
Injects a custom Clock (e.g. ManualClock in
tests).
Sourcepub fn max_capacity(self, capacity: u64) -> Self
pub fn max_capacity(self, capacity: u64) -> Self
Caps the number of entries held in L1 (None = unbounded).
Sourcepub fn lock_shards(self, shards: usize) -> Self
pub fn lock_shards(self, shards: usize) -> Self
Sets the number of single-flight lock shards (rounded up to a power of two).
Sourcepub fn remove_by_tag_behavior(self, behavior: RemoveByTagBehavior) -> Self
pub fn remove_by_tag_behavior(self, behavior: RemoveByTagBehavior) -> Self
Sets what remove_by_tag does to matched entries.
Sourcepub fn events_capacity(self, capacity: usize) -> Self
pub fn events_capacity(self, capacity: usize) -> Self
Sets the event channel’s buffer capacity.
Sourcepub fn distributed_locker(self, locker: Arc<dyn DistributedLocker>) -> Self
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.
Sourcepub fn plugin(self, plugin: Arc<dyn Plugin>) -> Self
pub fn plugin(self, plugin: Arc<dyn Plugin>) -> Self
Registers a Plugin to observe events and lifecycle.
Sourcepub fn distributed_circuit_breaker(self, duration: Duration) -> Self
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).
Sourcepub fn backplane_circuit_breaker(self, duration: Duration) -> Self
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).
Sourcepub fn auto_recovery(self, config: RecoveryConfig) -> Self
pub fn auto_recovery(self, config: RecoveryConfig) -> Self
Configures (or disables) auto-recovery of failed L2 / backplane operations.
Sourcepub fn default_options_provider(
self,
provider: Arc<dyn DefaultEntryOptionsProvider>,
) -> Self
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).
Sourcepub fn ignore_incoming_backplane(self, ignore: bool) -> Self
pub fn ignore_incoming_backplane(self, ignore: bool) -> Self
Drops all incoming backplane notifications (dangerous; for testing).
Sourcepub fn distributed_wire_version(self, version: impl AsRef<str>) -> Self
pub fn distributed_wire_version(self, version: impl AsRef<str>) -> Self
Sets the L2 wire-format version combined with distributed keys.
Sourcepub fn distributed_key_modifier_mode(self, mode: KeyModifierMode) -> Self
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).
Sourcepub fn disable_tagging(self, disable: bool) -> Self
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.
Sourcepub fn wait_for_initial_backplane_subscribe(self, wait: bool) -> Self
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.