pub struct TenantCache { /* private fields */ }Expand description
High-performance tenant cache.
Implementations§
Source§impl TenantCache
impl TenantCache
Sourcepub fn new(config: CacheConfig) -> Self
pub fn new(config: CacheConfig) -> Self
Create a new tenant cache with the given config.
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Create with default config.
Sourcepub fn config(&self) -> &CacheConfig
pub fn config(&self) -> &CacheConfig
Get the cache config.
Sourcepub fn lookup(&self, tenant_id: &TenantId) -> CacheLookup
pub fn lookup(&self, tenant_id: &TenantId) -> CacheLookup
Look up a tenant in the cache.
Sourcepub fn insert(&self, tenant_id: TenantId, context: TenantContext)
pub fn insert(&self, tenant_id: TenantId, context: TenantContext)
Insert a tenant into the cache.
Sourcepub fn insert_negative(&self, tenant_id: TenantId)
pub fn insert_negative(&self, tenant_id: TenantId)
Insert a negative entry (tenant not found).
Sourcepub fn invalidate(&self, tenant_id: &TenantId)
pub fn invalidate(&self, tenant_id: &TenantId)
Invalidate a specific tenant.
Sourcepub fn invalidate_if<F>(&self, predicate: F)
pub fn invalidate_if<F>(&self, predicate: F)
Invalidate all tenants matching a predicate.
Sourcepub fn metrics(&self) -> CacheMetrics
pub fn metrics(&self) -> CacheMetrics
Get cache metrics.
Sourcepub fn reset_metrics(&self)
pub fn reset_metrics(&self)
Reset metrics.
Sourcepub fn evict_expired(&self) -> usize
pub fn evict_expired(&self) -> usize
Evict expired entries.
Sourcepub fn mark_refreshing(&self, tenant_id: &TenantId) -> bool
pub fn mark_refreshing(&self, tenant_id: &TenantId) -> bool
Mark an entry as refreshing (to prevent thundering herd).
Sourcepub fn complete_refresh(&self, tenant_id: TenantId, context: TenantContext)
pub fn complete_refresh(&self, tenant_id: TenantId, context: TenantContext)
Complete a refresh with a new context.
Sourcepub async fn get_or_fetch<F, Fut>(
&self,
tenant_id: &TenantId,
fetch: F,
) -> Option<TenantContext>
pub async fn get_or_fetch<F, Fut>( &self, tenant_id: &TenantId, fetch: F, ) -> Option<TenantContext>
Get or fetch a tenant, using the cache.
Auto Trait Implementations§
impl !Freeze for TenantCache
impl !RefUnwindSafe for TenantCache
impl Send for TenantCache
impl Sync for TenantCache
impl Unpin for TenantCache
impl !UnwindSafe for TenantCache
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