Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn load<'a>(
        &'a self,
        session_id: &'a str,
    ) -> SessionFuture<'a, Option<HashMap<String, String>>>;
    fn save(
        &self,
        session_id: String,
        values: HashMap<String, String>,
        ttl_secs: u64,
    ) -> SessionFuture<'_, ()>;
    fn delete<'a>(&'a self, session_id: &'a str) -> SessionFuture<'a, bool>;

    // Provided method
    fn purge_expired(&self) -> usize { ... }
}
Expand description

Pluggable asynchronous session backend (in-memory sharded, Redis, PostgreSQL, etc.).

Required Methods§

Source

fn load<'a>( &'a self, session_id: &'a str, ) -> SessionFuture<'a, Option<HashMap<String, String>>>

Loads the unexpired key-value map for session_id, if present.

§Arguments
  • &'a self - Shared reference to self.
  • &'a str - Session identifier.
§Returns
  • SessionFuture<'a, Option<HashMap<String, String>>> - Session attributes if live.
Source

fn save( &self, session_id: String, values: HashMap<String, String>, ttl_secs: u64, ) -> SessionFuture<'_, ()>

Persists values under session_id with time-to-live ttl_secs.

§Arguments
  • String - Session identifier.
  • HashMap<String, String> - Session key-value attributes.
  • u64 - Session TTL in seconds.
§Returns
  • SessionFuture<'_, ()> - Completion future.
Source

fn delete<'a>(&'a self, session_id: &'a str) -> SessionFuture<'a, bool>

Deletes a session record from the store.

§Arguments
  • &'a self - Shared reference to self.
  • &'a str - Session identifier to delete.
§Returns
  • SessionFuture<'a, bool> - true when an entry existed and was deleted.

Provided Methods§

Source

fn purge_expired(&self) -> usize

Evicts expired sessions and returns the number reclaimed.

§Returns
  • usize - Count of expired sessions purged.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§