Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore: Send + Sync {
    // Required methods
    fn read<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<SessionData>, FrameworkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn write<'life0, 'life1, 'async_trait>(
        &'life0 self,
        session: &'life1 SessionData,
    ) -> Pin<Box<dyn Future<Output = Result<(), FrameworkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn destroy<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), FrameworkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn gc<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<u64, FrameworkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn destroy_for_user<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _user_id: i64,
        _except_session_id: Option<&'life1 str>,
    ) -> Pin<Box<dyn Future<Output = Result<u64, FrameworkError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Session store trait for different backends

Implement this trait to create custom session storage backends.

Required Methods§

Source

fn read<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<SessionData>, FrameworkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a session by its ID

Returns None if the session doesn’t exist or has expired.

Source

fn write<'life0, 'life1, 'async_trait>( &'life0 self, session: &'life1 SessionData, ) -> Pin<Box<dyn Future<Output = Result<(), FrameworkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Write a session to storage

Creates a new session if it doesn’t exist, updates if it does.

Source

fn destroy<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), FrameworkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Destroy a session by its ID

Source

fn gc<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, FrameworkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Garbage collect expired sessions

Returns the number of sessions cleaned up.

Provided Methods§

Source

fn destroy_for_user<'life0, 'life1, 'async_trait>( &'life0 self, _user_id: i64, _except_session_id: Option<&'life1 str>, ) -> Pin<Box<dyn Future<Output = Result<u64, FrameworkError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Destroy all sessions for a user, optionally keeping one session.

Used for “logout other devices” (pass current session ID to keep) or “logout everywhere” (pass None). Returns the number of destroyed sessions.

Default implementation returns an error; override in drivers that support it.

Implementors§