pub struct ShardedTenantCache { /* private fields */ }Expand description
A sharded cache for high-concurrency scenarios.
Uses multiple shards to reduce lock contention under heavy load.
Implementations§
Source§impl ShardedTenantCache
impl ShardedTenantCache
Sourcepub fn new(shard_count: usize, config: CacheConfig) -> Self
pub fn new(shard_count: usize, config: CacheConfig) -> Self
Create a new sharded cache.
Sourcepub fn high_concurrency(max_entries: usize) -> Self
pub fn high_concurrency(max_entries: usize) -> Self
Create with reasonable defaults for high-concurrency.
Sourcepub fn lookup(&self, tenant_id: &TenantId) -> CacheLookup
pub fn lookup(&self, tenant_id: &TenantId) -> CacheLookup
Look up a tenant.
Sourcepub fn insert(&self, tenant_id: TenantId, context: TenantContext)
pub fn insert(&self, tenant_id: TenantId, context: TenantContext)
Insert a tenant.
Sourcepub fn insert_negative(&self, tenant_id: TenantId)
pub fn insert_negative(&self, tenant_id: TenantId)
Insert a negative entry.
Sourcepub fn invalidate(&self, tenant_id: &TenantId)
pub fn invalidate(&self, tenant_id: &TenantId)
Invalidate a tenant.
Sourcepub fn metrics(&self) -> CacheMetrics
pub fn metrics(&self) -> CacheMetrics
Get aggregated metrics.
Sourcepub fn evict_expired(&self) -> usize
pub fn evict_expired(&self) -> usize
Evict expired entries from all shards.
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.
Auto Trait Implementations§
impl Freeze for ShardedTenantCache
impl !RefUnwindSafe for ShardedTenantCache
impl Send for ShardedTenantCache
impl Sync for ShardedTenantCache
impl Unpin for ShardedTenantCache
impl UnsafeUnpin for ShardedTenantCache
impl !UnwindSafe for ShardedTenantCache
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