pub struct CachedSecretProvider<P: SecretProvider> { /* private fields */ }Expand description
Wraps a SecretProvider with a bounded in-memory cache.
Cached values are returned within the configured TTL. After expiry the inner provider is called again and the cache is refreshed. Expired entries are removed on the next write rather than lingering until their name is requested again, and the cache never holds more than its capacity.
§Example
use adk_auth::secrets::{CachedSecretProvider, SecretProvider};
use std::time::Duration;
let cached = CachedSecretProvider::new(inner_provider, Duration::from_secs(300))
.with_max_entries(32);
let secret = cached.get_secret("my-key").await?;
// A rotated secret can be dropped before its TTL elapses.
cached.invalidate("my-key").await;Implementations§
Source§impl<P: SecretProvider> CachedSecretProvider<P>
impl<P: SecretProvider> CachedSecretProvider<P>
Sourcepub fn new(inner: P, ttl: Duration) -> Self
pub fn new(inner: P, ttl: Duration) -> Self
Create a new cached provider wrapping inner with the given TTL.
Sourcepub fn with_max_entries(self, max_entries: usize) -> Self
pub fn with_max_entries(self, max_entries: usize) -> Self
Set how many distinct secret names may be cached at once.
When the cache is full the least recently used entry is dropped. A capacity of zero disables caching. Without a bound, code that derives secret names from input can grow the cache for the lifetime of the process.
Sourcepub async fn invalidate(&self, name: &str)
pub async fn invalidate(&self, name: &str)
Drop a single cached secret, zeroizing its value.
Call this when a secret is rotated or revoked so the old value is not served for the remainder of its TTL.
Sourcepub async fn invalidate_all(&self)
pub async fn invalidate_all(&self)
Drop every cached secret, zeroizing the values.
Sourcepub async fn purge_expired(&self) -> usize
pub async fn purge_expired(&self) -> usize
Drop every expired entry and return how many were removed.
Expiry is otherwise noticed only when the same name is read again, so this is what a caller uses to bound residency without waiting for traffic.
Trait Implementations§
Source§impl<P: SecretProvider> Debug for CachedSecretProvider<P>
Redacts cached values so a debug print cannot leak a secret.
impl<P: SecretProvider> Debug for CachedSecretProvider<P>
Redacts cached values so a debug print cannot leak a secret.