pub struct OperationConfig {
pub ttl_override: Option<Duration>,
pub retry_count: u32,
}Expand description
Configuration for per-operation overrides.
This allows you to override TTL and retry behavior for individual cache operations,
without affecting the global settings on the CacheExpander.
§Setup-Time vs Per-Operation Configuration
- Setup-time configuration: Set once on
CacheExpanderusingwith_metrics()orwith_ttl_policy(). These affect all operations. - Per-operation configuration: Use
OperationConfigto override settings for a specific cache operation.
§Example
ⓘ
use cache_kit::OperationConfig;
use std::time::Duration;
// Override TTL and add retry for this specific operation
let config = OperationConfig::default()
.with_ttl(Duration::from_secs(300))
.with_retry(3);
expander.with_config(&mut feeder, &repo, strategy, config).await?;Fields§
§ttl_override: Option<Duration>Override the default TTL for this operation only.
§Precedence and Conflict Resolution
When both ttl_override and the expander’s ttl_policy could apply:
- If
Some(duration): Use this override (takes precedence) - If
None: Fall back to the expander’sttl_policy
This allows per-operation exceptions without changing global settings.
§Example: Flash Sale Override
ⓘ
use cache_kit::{CacheExpander, OperationConfig, observability::TtlPolicy};
use std::time::Duration;
// Setup: Default 1-hour cache for all entities
let expander = CacheExpander::new(backend)
.with_ttl_policy(TtlPolicy::Fixed(Duration::from_secs(3600)));
// Normal operation: Uses 1-hour TTL from global policy
expander.with(&mut feeder, &repo, CacheStrategy::Refresh).await?;
// Flash sale: Override to 60 seconds (one-time exception)
let flash_config = OperationConfig::default()
.with_ttl(Duration::from_secs(60)); // Overrides global 1h policy
expander.with_config(&mut feeder, &repo, CacheStrategy::Refresh, flash_config).await?;retry_count: u32Number of retry attempts for this operation (0 = no retry).
If the operation fails, it will be retried up to this many times with exponential backoff.
Implementations§
Source§impl OperationConfig
impl OperationConfig
Trait Implementations§
Source§impl Clone for OperationConfig
impl Clone for OperationConfig
Source§fn clone(&self) -> OperationConfig
fn clone(&self) -> OperationConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for OperationConfig
impl Debug for OperationConfig
Source§impl Default for OperationConfig
impl Default for OperationConfig
Source§fn default() -> OperationConfig
fn default() -> OperationConfig
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for OperationConfig
impl RefUnwindSafe for OperationConfig
impl Send for OperationConfig
impl Sync for OperationConfig
impl Unpin for OperationConfig
impl UnwindSafe for OperationConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more