pub struct CachedKeySet<C, S> { /* private fields */ }Expand description
A caching wrapper for any KeySource implementation.
This wrapper uses the cache-aside pattern: it first checks the cache for a key, and only fetches from the underlying source on a cache miss. Retrieved keys are then stored in the cache for future requests.
§Type Parameters
C- The cache implementation (must implementKeyCache)S- The underlying key source (must implementKeySource)
§Examples
ⓘ
use jwk_simple::{CachedKeySet, InMemoryKeyCache, RemoteKeySet, KeySource};
use std::time::Duration;
use std::sync::Arc;
// Create a cached remote JWKS
let cache = InMemoryKeyCache::new(Duration::from_secs(300));
let remote = RemoteKeySet::new("https://example.com/.well-known/jwks.json");
let cached = CachedKeySet::new(cache, remote);
// First call fetches from remote, caches the key
let key = cached.get_key("kid").await?;
// Subsequent calls use the cache
let key = cached.get_key("kid").await?;Implementations§
Source§impl<C, S> CachedKeySet<C, S>
impl<C, S> CachedKeySet<C, S>
Source§impl<S> CachedKeySet<InMemoryKeyCache, S>
impl<S> CachedKeySet<InMemoryKeyCache, S>
Sourcepub fn with_ttl(source: S, ttl: Duration) -> Self
Available on crate feature cache-inmemory only.
pub fn with_ttl(source: S, ttl: Duration) -> Self
cache-inmemory only.Creates a new cached key source with in-memory caching and the specified TTL.
Sourcepub fn with_default_ttl(source: S) -> Self
Available on crate feature cache-inmemory only.
pub fn with_default_ttl(source: S) -> Self
cache-inmemory only.Creates a new cached key source with in-memory caching and the default TTL.
Sourcepub async fn invalidate(&self)
Available on crate feature cache-inmemory only.
pub async fn invalidate(&self)
cache-inmemory only.Invalidates the cache, forcing fresh fetches on subsequent requests.
Sourcepub async fn invalidate_key(&self, kid: &str)
Available on crate feature cache-inmemory only.
pub async fn invalidate_key(&self, kid: &str)
cache-inmemory only.Removes a specific key from the cache.
Trait Implementations§
Source§impl<C, S> KeySource for CachedKeySet<C, S>
impl<C, S> KeySource for CachedKeySet<C, S>
Auto Trait Implementations§
impl<C, S> Freeze for CachedKeySet<C, S>
impl<C, S> RefUnwindSafe for CachedKeySet<C, S>where
C: RefUnwindSafe,
S: RefUnwindSafe,
impl<C, S> Send for CachedKeySet<C, S>
impl<C, S> Sync for CachedKeySet<C, S>
impl<C, S> Unpin for CachedKeySet<C, S>
impl<C, S> UnwindSafe for CachedKeySet<C, S>where
C: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more