Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Cachet Memory
High-performance in-memory cache tier.
This crate provides InMemoryCache, a concurrent in-memory cache with
configurable eviction policies (TinyLFU by default) for excellent hit rates.
Use InMemoryCacheBuilder to configure capacity, TTL, TTI, and eviction policy.
Quick Start
use Duration;
use InMemoryCacheBuilder;
use ;
let cache = new
.max_capacity
.time_to_live
.build
.expect;
cache
.insert
.await
.unwrap;
let value = cache.get.await.unwrap;
assert_eq!;
Features
- Capacity limits: Set maximum entry count with automatic eviction
- Eviction policies: Choose between
TinyLFU(default) and LRU viaEvictionPolicy - TTL/TTI: Configure time-to-live and time-to-idle expiration
- Per-entry TTL: Honors
CacheEntry::expires_afterfor per-entry expiration - Eviction notifications: Observe removals via
InMemoryCacheBuilder::on_evictionor opt into host-side telemetry withInMemoryCacheBuilder::with_eviction_telemetry - Thread-safe: Safe for concurrent access from multiple tasks
- Zero external types: Builder API keeps implementation details private
Eviction Notifications
Two complementary hooks are available for observing entry removals:
InMemoryCacheBuilder::on_evictiontakes a closure invoked with aRemovalCausefor every removal (capacity, expiry, explicit, or replace). Use this for custom side effects.InMemoryCacheBuilder::with_eviction_telemetryis a marker that the host crate (cachet) recognizes viaCacheBuilder::memory_withand uses to install a built-in listener that emitscache.evictionfor capacity removals andcache.expiredfor background TTL/TTI expiry. Explicit and replaced removals are intentionally not surfaced — they are already covered by the host’scache.invalidatedandcache.insertedevents. The marker has no effect whenInMemoryCacheis built directly without a host.
Expiration Behavior
This tier supports three independent expiration mechanisms. When multiple are active, the shortest duration wins - an entry is evicted at the earliest of:
- The per-entry TTL from
CacheEntry::expires_after - The cache-wide TTL from
InMemoryCacheBuilder::time_to_live - The cache-wide TTI from
InMemoryCacheBuilder::time_to_idle
This means the builder-level TTL/TTI acts as an upper bound on per-entry TTL. A per-entry TTL longer than the builder TTL will be silently clamped to the builder value. To give per-entry TTL full control, either leave the builder-level TTL/TTI unset or set them to a sufficiently high ceiling.