Expand description
amalgam — a robust, multi-level, fail-safe cache for Rust.
An amalgam is a fusion of metals; this crate is a faithful, idiomatic Rust port of the resiliency model pioneered by .NET’s FusionCache. It fuses an in-memory L1 cache with an optional distributed L2 cache and gives you the features that make a cache robust rather than merely fast:
- Cache-stampede protection — only one factory runs per key (single-flight).
- Fail-safe — serve a stale value when the factory fails, instead of erroring.
- Soft / hard timeouts — a slow factory can return a stale value immediately and finish in the background.
- Eager refresh — refresh proactively before expiration, off the hot path.
- Adaptive caching — the factory can change the entry’s options per call.
- Conditional refresh — HTTP-style
NotModifiedreuse of a stale value. - Tagging — invalidate many entries at once, lazily, by tag.
- L1 + L2 + backplane — pluggable distributed cache and multi-node sync.
See PORTING.md for the C#→Rust translation methodology and docs/PARITY.md
for the feature-by-feature mapping to FusionCache.
Re-exports§
pub use backplane::Backplane;pub use backplane::BackplaneAction;pub use backplane::BackplaneMessage;pub use backplane::InProcessBackplane;pub use cache::Cache;pub use cache::CacheBuilder;pub use circuit::CircuitBreaker;pub use distributed::DistributedCache;pub use distributed::DistributedEntry;pub use distributed::DistributedSerializer;pub use distributed::InMemoryDistributedCache;pub use distributed::JsonSerializer;pub use distributed_lock::DistributedLocker;pub use distributed_lock::InMemoryDistributedLocker;pub use error::Error;pub use error::FactoryError;pub use error::Result;pub use events::CacheEvent;pub use events::CircuitComponent;pub use events::Events;pub use factory::FactoryContext;pub use factory::FactoryProduct;pub use factory::ModifiedBuilder;pub use maybe::MaybeValue;pub use options::EagerThreshold;pub use options::EntryOptions;pub use options::KeyModifierMode;pub use options::Priority;pub use options::RemoveByTagBehavior;pub use plugins::Plugin;pub use plugins::PluginHost;pub use recovery::AutoRecoveryService;pub use recovery::RecoveryAction;pub use recovery::RecoveryConfig;pub use recovery::RecoveryExecutor;pub use recovery::RecoveryItem;pub use registry::CacheRegistry;pub use registry::DefaultEntryOptionsProvider;pub use tags::Tag;pub use time::Clock;pub use time::ManualClock;pub use time::SystemClock;pub use time::Timeout;pub use time::Timestamp;
Modules§
- backplane
- The backplane: multi-node invalidation messaging.
- cache
- The
Cachetype — the heart of the library. - circuit
- A circuit breaker for L2 / backplane operations.
- distributed
- L2 distributed cache: the wire envelope, a serializer abstraction, the
DistributedCachebackend trait, and an in-memory reference backend. - distributed_
lock - Cross-node single-flight: the
DistributedLockerseam. - entry
- The internal cache entry envelope: value plus the metadata that drives freshness, fail-safe and eager-refresh decisions.
- error
- Error types.
- events
- The event hub.
- factory
- The factory execution context and its product.
- locking
- Single-flight locking for cache-stampede protection.
- maybe
- The
MaybeValuetype: “a value, or explicitly no value”. - memory
- The L1 (in-memory) store, backed by
moka. - observability
- Metrics, exposed as a
Plugin(featuremetrics). - options
- Per-entry options (
EntryOptions) and their supporting value types. - plugins
- The plugin seam.
- recovery
- Auto-recovery: retry L2 / backplane operations that failed transiently.
- registry
- Named caches and dynamic default options.
- serializers
- Additional L2 serializers behind feature flags.
- tags
- Tagging:
Tagvalues and the lazyTagRegistrythat powersCache::remove_by_tagandCache::clear. - time
- Time abstractions.