pub struct DocumentCache { /* private fields */ }Expand description
Generic JSON document cache shared by metadata and JWKS layers.
Implementations§
Source§impl DocumentCache
impl DocumentCache
Sourcepub fn new(
fetcher: DocumentFetcherFn,
refresh_seconds: u64,
document_type: impl Into<String>,
on_change: Option<DocumentChangeCallback>,
) -> Arc<Self> ⓘ
pub fn new( fetcher: DocumentFetcherFn, refresh_seconds: u64, document_type: impl Into<String>, on_change: Option<DocumentChangeCallback>, ) -> Arc<Self> ⓘ
Build a new cache with default error factory (transport_error).
Sourcepub fn with_error_factory(
fetcher: DocumentFetcherFn,
refresh_seconds: u64,
document_type: impl Into<String>,
on_change: Option<DocumentChangeCallback>,
error_factory: Box<dyn Fn(&str) -> AuthplaneError + Send + Sync>,
) -> Arc<Self> ⓘ
pub fn with_error_factory( fetcher: DocumentFetcherFn, refresh_seconds: u64, document_type: impl Into<String>, on_change: Option<DocumentChangeCallback>, error_factory: Box<dyn Fn(&str) -> AuthplaneError + Send + Sync>, ) -> Arc<Self> ⓘ
Build a cache with a custom error factory (e.g. JwksFetchError).
Sourcepub fn document_type(&self) -> &str
pub fn document_type(&self) -> &str
Document type label.
Sourcepub fn refresh_seconds(&self) -> u64
pub fn refresh_seconds(&self) -> u64
Configured refresh interval in seconds.
Sourcepub async fn get(&self, force_refresh: bool) -> Result<Value, AuthplaneError>
pub async fn get(&self, force_refresh: bool) -> Result<Value, AuthplaneError>
Return the cached document, fetching or refreshing as needed.
Concurrent callers serialise behind an internal mutex so only one fetch is in flight at a time. On fetch errors a stale cache is served, silently — the crate carries no logging facility, so the failed refresh leaves no trace; if no cache existed yet, the error factory is invoked.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DocumentCache
impl !RefUnwindSafe for DocumentCache
impl !UnwindSafe for DocumentCache
impl Send for DocumentCache
impl Sync for DocumentCache
impl Unpin for DocumentCache
impl UnsafeUnpin for DocumentCache
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