pub struct AuthCache {
inner: Arc<RwLock<HashMap<String, AuthEntry>>>,
locks: Arc<Mutex<HashMap<String, Arc<Mutex<()>>>>>,
}Expand description
A time-bounded, per-request-key cache for authorization decisions.
Wraps arbitrary async validator functions so that the (potentially
expensive) Python callback is only invoked once per (access_key, bucket, query) tuple within the configured TTL window.
Concurrent cache misses for the same key are serialized via a per-key
[Mutex] to avoid thundering-herd stampedes.
Fields§
§inner: Arc<RwLock<HashMap<String, AuthEntry>>>§locks: Arc<Mutex<HashMap<String, Arc<Mutex<()>>>>>Implementations§
Source§impl AuthCache
impl AuthCache
pub fn new() -> Self
pub async fn get_or_validate<F, Fut, E>( &self, key: &str, ttl: Duration, validator_fn: F, ) -> Result<bool, E>
Sourcepub fn insert(&self, key: String, authorized: bool, ttl: Duration)
pub fn insert(&self, key: String, authorized: bool, ttl: Duration)
Pre-populate the cache with a known decision for key.
Sourcepub fn invalidate(&self, key: &str)
pub fn invalidate(&self, key: &str)
Evict the cached entry for key, forcing re-validation on the next request.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AuthCache
impl !RefUnwindSafe for AuthCache
impl Send for AuthCache
impl Sync for AuthCache
impl Unpin for AuthCache
impl UnsafeUnpin for AuthCache
impl !UnwindSafe for AuthCache
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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