Skip to main content

CachedSecretProvider

Struct CachedSecretProvider 

Source
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>

Source

pub fn new(inner: P, ttl: Duration) -> Self

Create a new cached provider wrapping inner with the given TTL.

Source

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.

Source

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.

Source

pub async fn invalidate_all(&self)

Drop every cached secret, zeroizing the values.

Source

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.

Source

pub async fn len(&self) -> usize

Number of entries currently held, expired or not.

Source

pub async fn is_empty(&self) -> bool

Whether the cache holds no entries.

Trait Implementations§

Source§

impl<P: SecretProvider> Debug for CachedSecretProvider<P>

Redacts cached values so a debug print cannot leak a secret.

Source§

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

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

impl<P: SecretProvider> SecretProvider for CachedSecretProvider<P>

Source§

fn get_secret<'life0, 'life1, 'async_trait>( &'life0 self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, AdkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve a secret value by name. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more