pub struct InMemoryDistributedStorage { /* private fields */ }Expand description
In-memory distributed session storage implementation 内存分布式 Session 存储实现
For testing and development purposes 用于测试和开发目的
Implementations§
Trait Implementations§
Source§impl Default for InMemoryDistributedStorage
impl Default for InMemoryDistributedStorage
Source§impl DistributedSessionStorage for InMemoryDistributedStorage
impl DistributedSessionStorage for InMemoryDistributedStorage
Source§fn save_session<'life0, 'async_trait>(
&'life0 self,
session: DistributedSession,
_ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save_session<'life0, 'async_trait>(
&'life0 self,
session: DistributedSession,
_ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Save session to memory storage | 保存会话到内存存储
§Implementation Details | 实现细节
- Stores session in main HashMap by session_id 在主 HashMap 中按 session_id 存储会话
- Updates login_index for quick user lookup 更新 login_index 以快速查找用户
§Note | 注意
TTL is ignored in memory storage (for simplicity). In production, use Redis or similar with built-in TTL support. 内存存储中忽略 TTL(为简化实现)。 在生产环境中,使用 Redis 或类似的内置 TTL 支持的存储。
Source§fn get_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<DistributedSession>, SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<DistributedSession>, SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get session from memory storage | 从内存存储获取会话
§Returns | 返回
Ok(Some(session))- Session found | 找到会话Ok(None)- Session not found | 未找到会话
Source§fn delete_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete_session<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete session from memory storage | 从内存存储删除会话
§Implementation Details | 实现细节
- Removes session from main HashMap 从主 HashMap 中移除会话
- Removes session_id from login_index 从 login_index 中移除 session_id
- Cleans up empty index entries 清理空的索引条目
Source§fn get_sessions_by_login_id<'life0, 'life1, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<DistributedSession>, SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_sessions_by_login_id<'life0, 'life1, 'async_trait>(
&'life0 self,
login_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<DistributedSession>, SaTokenError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get all sessions for a user | 获取用户的所有会话
§Implementation Details | 实现细节
- Looks up session_ids in login_index 在 login_index 中查找 session_ids
- Retrieves full session data for each session_id 为每个 session_id 检索完整的会话数据
- Filters out any missing sessions (cleanup) 过滤掉任何缺失的会话(清理)
§Returns | 返回
Vector of all active sessions for the user 用户所有活跃会话的向量
Auto Trait Implementations§
impl Freeze for InMemoryDistributedStorage
impl !RefUnwindSafe for InMemoryDistributedStorage
impl Send for InMemoryDistributedStorage
impl Sync for InMemoryDistributedStorage
impl Unpin for InMemoryDistributedStorage
impl !UnwindSafe for InMemoryDistributedStorage
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more