1use crate::permission::Permission;
2use crate::types::{PrincipalId, RoleId, TenantId};
3use async_trait::async_trait;
4
5#[async_trait]
7pub trait Cache: Send + Sync {
8 async fn get_permissions(
10 &self,
11 tenant: &TenantId,
12 principal: &PrincipalId,
13 ) -> Option<Vec<Permission>>;
14
15 async fn set_permissions(
17 &self,
18 tenant: &TenantId,
19 principal: &PrincipalId,
20 perms: Vec<Permission>,
21 );
22
23 async fn invalidate_principal(&self, tenant: &TenantId, principal: &PrincipalId);
25
26 async fn invalidate_role(&self, tenant: &TenantId, role: &RoleId);
28
29 async fn invalidate_tenant(&self, tenant: &TenantId);
31}
32
33#[derive(Debug, Default, Clone, Copy)]
35pub struct NoCache;
36
37#[async_trait]
38impl Cache for NoCache {
39 async fn get_permissions(
40 &self,
41 _tenant: &TenantId,
42 _principal: &PrincipalId,
43 ) -> Option<Vec<Permission>> {
44 None
45 }
46
47 async fn set_permissions(
48 &self,
49 _tenant: &TenantId,
50 _principal: &PrincipalId,
51 _perms: Vec<Permission>,
52 ) {
53 }
54
55 async fn invalidate_principal(&self, _tenant: &TenantId, _principal: &PrincipalId) {}
56
57 async fn invalidate_role(&self, _tenant: &TenantId, _role: &RoleId) {}
58
59 async fn invalidate_tenant(&self, _tenant: &TenantId) {}
60}