#[non_exhaustive]pub struct TenantCache { /* private fields */ }Expand description
Cache facade permanently bound to one authenticated tenant context.
Every operation derives the backend key from the immutable tenant identity.
The wrapper intentionally has no global flush; callers may only forget
explicit keys inside their tenant namespace.
Implementations§
Source§impl TenantCache
impl TenantCache
Sourcepub fn from_context(cache: Cache, context: &TenantContext) -> Self
pub fn from_context(cache: Cache, context: &TenantContext) -> Self
Binds a cache to a tenant already validated by authentication.
Sourcepub fn tenant_id(&self) -> &str
pub fn tenant_id(&self) -> &str
Returns the authenticated tenant identifier bound to this instance.
Sourcepub fn namespaced_key(&self, logical_key: &str) -> Result<String, CacheError>
pub fn namespaced_key(&self, logical_key: &str) -> Result<String, CacheError>
Returns the canonical backend key within this instance’s tenant namespace.
The key is tenants:<tenant>:<logical_key>. In the tenant segment %
is written as %25 and : as %3A, so a logical key containing :
can never alias another tenant’s namespace.
Sourcepub async fn get(
&self,
logical_key: &str,
) -> Result<Option<Arc<String>>, CacheError>
pub async fn get( &self, logical_key: &str, ) -> Result<Option<Arc<String>>, CacheError>
Retrieves a value only from this instance’s tenant namespace.
Sourcepub async fn put(
&self,
logical_key: &str,
value: &str,
ttl_secs: Option<u64>,
) -> Result<(), CacheError>
pub async fn put( &self, logical_key: &str, value: &str, ttl_secs: Option<u64>, ) -> Result<(), CacheError>
Stores a value only inside this instance’s tenant namespace.
Sourcepub async fn has(&self, logical_key: &str) -> Result<bool, CacheError>
pub async fn has(&self, logical_key: &str) -> Result<bool, CacheError>
Checks for a value only inside this instance’s tenant namespace.