OperationConfig

Struct OperationConfig 

Source
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 CacheExpander using with_metrics() or with_ttl_policy(). These affect all operations.
  • Per-operation configuration: Use OperationConfig to 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’s ttl_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: u32

Number 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

Source

pub fn with_ttl(self, ttl: Duration) -> Self

Override TTL for this operation.

§Example
let config = OperationConfig::default()
    .with_ttl(Duration::from_secs(300));
Source

pub fn with_retry(self, count: u32) -> Self

Set retry count for this operation.

§Example
let config = OperationConfig::default()
    .with_retry(3);  // Retry up to 3 times on failure

Trait Implementations§

Source§

impl Clone for OperationConfig

Source§

fn clone(&self) -> OperationConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OperationConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OperationConfig

Source§

fn default() -> OperationConfig

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.