Skip to main content

hyperlane_plugin_session/
trait.rs

1use super::*;
2
3/// Pluggable asynchronous session backend (in-memory sharded, Redis, PostgreSQL, etc.).
4pub trait SessionStore: Send + Sync + 'static {
5    /// Loads the unexpired key-value map for `session_id`, if present.
6    ///
7    /// # Arguments
8    ///
9    /// - `&'a self` - Shared reference to self.
10    /// - `&'a str` - Session identifier.
11    ///
12    /// # Returns
13    ///
14    /// - `SessionFuture<'a, Option<HashMap<String, String>>>` - Session attributes if live.
15    fn load<'a>(
16        &'a self,
17        session_id: &'a str,
18    ) -> SessionFuture<'a, Option<HashMap<String, String>>>;
19
20    /// Persists `values` under `session_id` with time-to-live `ttl_secs`.
21    ///
22    /// # Arguments
23    ///
24    /// - `String` - Session identifier.
25    /// - `HashMap<String, String>` - Session key-value attributes.
26    /// - `u64` - Session TTL in seconds.
27    ///
28    /// # Returns
29    ///
30    /// - `SessionFuture<'_, ()>` - Completion future.
31    fn save(
32        &self,
33        session_id: String,
34        values: HashMap<String, String>,
35        ttl_secs: u64,
36    ) -> SessionFuture<'_, ()>;
37
38    /// Deletes a session record from the store.
39    ///
40    /// # Arguments
41    ///
42    /// - `&'a self` - Shared reference to self.
43    /// - `&'a str` - Session identifier to delete.
44    ///
45    /// # Returns
46    ///
47    /// - `SessionFuture<'a, bool>` - `true` when an entry existed and was deleted.
48    fn delete<'a>(&'a self, session_id: &'a str) -> SessionFuture<'a, bool>;
49
50    /// Evicts expired sessions and returns the number reclaimed.
51    ///
52    /// # Returns
53    ///
54    /// - `usize` - Count of expired sessions purged.
55    fn purge_expired(&self) -> usize {
56        0
57    }
58}