pub struct CacheKitBuilder { /* private fields */ }Expand description
Fluent builder for CacheKit.
Implementations§
Source§impl CacheKitBuilder
impl CacheKitBuilder
Sourcepub fn backend(self, backend: SharedBackend) -> Self
pub fn backend(self, backend: SharedBackend) -> Self
Set the storage backend.
Sourcepub fn default_ttl(self, ttl: Duration) -> Self
pub fn default_ttl(self, ttl: Duration) -> Self
Override the default TTL (used when no per-call TTL is specified).
Sourcepub fn namespace(self, ns: impl Into<String>) -> Self
pub fn namespace(self, ns: impl Into<String>) -> Self
Set a namespace prefix. All keys will be stored as {namespace}:{key}.
Sourcepub fn max_payload_bytes(self, limit: usize) -> Self
pub fn max_payload_bytes(self, limit: usize) -> Self
Set the maximum accepted payload size in bytes.
Sourcepub fn l1_capacity(self, capacity: usize) -> Self
pub fn l1_capacity(self, capacity: usize) -> Self
Set the L1 cache capacity (max entries).
Sourcepub fn swr_enabled(self, enabled: bool) -> Self
pub fn swr_enabled(self, enabled: bool) -> Self
Enable or disable L1 stale-while-revalidate (default: enabled, matching the Python and TypeScript SDKs).
With SWR on, an L1 hit older than swr_threshold_ratio of its TTL is
still served immediately, and the #[cachekit] macro schedules
exactly one background refresh (deduplicated through
CacheKit::single_flight, in-process and — on lock-capable
backends — across processes). A hard-expired entry is never served:
it falls through to a normal blocking miss.
Native targets only: this knob does not exist on wasm32, under the
unsync feature, or without l1 — calling it there is a compile
error rather than a silent no-op.
Sourcepub fn swr_threshold_ratio(self, ratio: f64) -> Self
pub fn swr_threshold_ratio(self, ratio: f64) -> Self
Set the SWR freshness threshold as a fraction of each L1 entry’s TTL (default: 0.5, matching the Python and TypeScript SDKs).
An entry is fresh until it has lived ratio × TTL (±10% jitter,
drawn once when the entry is inserted, to de-synchronise refreshes
across processes), then stale — served immediately with a background
refresh — until hard expiry. Mirrors cachekit-py’s
swr_threshold_ratio semantics (elapsed-lifetime fraction). Must be in
(0.0, 1.0]; validated at Self::build.
Sourcepub fn reliability(self, config: ReliabilityConfig) -> Self
pub fn reliability(self, config: ReliabilityConfig) -> Self
Wrap the backend in the reliability stack (retry with exponential
backoff + jitter, circuit breaker, backpressure) — see
crate::reliability.
Enabled by default with production settings by the production,
encrypted, and io intent presets; off for minimal and for
manually-built clients. To opt a preset out, pass
ReliabilityConfig::disabled()
— a disabled config applies no wrapping at all.
Sourcepub fn encryption_from_bytes(
self,
master_key: &[u8],
tenant_id: &str,
) -> Result<Self, CachekitError>
pub fn encryption_from_bytes( self, master_key: &[u8], tenant_id: &str, ) -> Result<Self, CachekitError>
Configure encryption from raw master key bytes and tenant ID.
The master key must be at least 16 bytes (32 recommended). Keys are derived per-tenant via HKDF-SHA256.
Sourcepub fn encryption(
self,
hex_key: &str,
tenant_id: &str,
) -> Result<Self, CachekitError>
pub fn encryption( self, hex_key: &str, tenant_id: &str, ) -> Result<Self, CachekitError>
Configure encryption from a hex-encoded master key string.
Convenience wrapper that hex-decodes then delegates to
Self::encryption_from_bytes.