Expand description
Cache policy for caching successful results.
The cache policy stores successful results and returns them for subsequent calls, reducing load on underlying services.
§Examples
use do_over::{policy::Policy, cache::Cache, error::DoOverError};
use std::time::Duration;
// Cache results for 60 seconds
let policy = Cache::<String>::new(Duration::from_secs(60));
// First call executes the operation
let result: Result<String, DoOverError<String>> = policy.execute(|| async {
Ok("expensive_result".to_string())
}).await;
// Subsequent calls return cached value (until TTL expires)Structs§
- Cache
- A policy that caches successful results for a specified duration.
- Typed
Cache - A typed cache that stores and returns values of a specific type.