Skip to main content

KeyCache

Trait KeyCache 

Source
pub trait KeyCache {
    // Required methods
    fn get<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<KeySet>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn set<'life0, 'async_trait>(
        &'life0 self,
        keyset: KeySet,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A trait for caching key sets used by CachedKeyStore.

This trait is primarily an extension point for library integrators who need a custom cache backend (in-memory, KV store, persistent storage, etc.). Most users should use CachedKeyStore with a provided cache implementation, such as MokaKeyCache.

CachedKeyStore does not coordinate concurrent refreshes. Cache backends used in concurrent contexts should provide their own internal synchronization and atomicity guarantees for get/set/clear operations.

The cache stores the entire KeySet as a single unit, which matches how JWKS endpoints work (they always return the full set). This avoids the N+1 fetch problem that per-key caching would cause.

Required Methods§

Source

fn get<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<KeySet>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets the cached key set.

Returns None if the cache is empty or has expired.

Source

fn set<'life0, 'async_trait>( &'life0 self, keyset: KeySet, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores a key set in the cache.

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clears the cache.

Implementors§

Source§

impl KeyCache for MokaKeyCache

Available on crate feature moka and non-WebAssembly only.