Rust

breaker

Module

[CircuitBreaker]: an adapter whose failures fall back instead of failing, behind a utopia_circuit_breaker::CircuitBreaker that stops calling a failing backend.

Contents

use utopia_cache::CircuitBreaker;
Rust
pub struct CircuitBreaker<A>

An adapter behind a circuit breaker: while the backend fails, operations return a fallback (a miss, false, an empty list, 0) instead of an error, and an open circuit skips the backend entirely.

Rust
use php_std::types::Value;
use utopia_cache::{Adapter, CircuitBreaker, Memory};
use utopia_circuit_breaker::{CircuitBreaker as Breaker, Options};

let cache = CircuitBreaker::new(Memory::new(), Breaker::new(Options::default()).unwrap());
assert!(cache.save("key", &Value::from("value"), "", 0).await?);
assert_eq!(cache.load("key", 60, "").await?, Some(Value::from("value")));