pub trait SessionStorageBackend:
Debug
+ Send
+ Sync {
// Required methods
fn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
record: SessionRecordRef<'life2>,
) -> Pin<Box<dyn Future<Output = Result<(), CreateError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn update<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
record: SessionRecordRef<'life2>,
) -> Pin<Box<dyn Future<Output = Result<(), UpdateError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn update_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), UpdateTtlError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn load<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<Option<SessionRecord>, LoadError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), DeleteError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn change_id<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
old_id: &'life1 SessionId,
new_id: &'life2 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), ChangeIdError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn delete_expired<'life0, 'async_trait>(
&'life0 self,
batch_size: Option<NonZeroUsize>,
) -> Pin<Box<dyn Future<Output = Result<usize, DeleteExpiredError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
The interface of a session storage backend.
Required Methods§
Sourcefn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
record: SessionRecordRef<'life2>,
) -> Pin<Box<dyn Future<Output = Result<(), CreateError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn create<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
record: SessionRecordRef<'life2>,
) -> Pin<Box<dyn Future<Output = Result<(), CreateError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Creates a new session record in the store using the provided ID.
Sourcefn update<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
record: SessionRecordRef<'life2>,
) -> Pin<Box<dyn Future<Output = Result<(), UpdateError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn update<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
record: SessionRecordRef<'life2>,
) -> Pin<Box<dyn Future<Output = Result<(), UpdateError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Update the state of an existing session in the store.
It overwrites the existing record with the provided one.
Sourcefn update_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), UpdateTtlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
id: &'life1 SessionId,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), UpdateTtlError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Update the TTL of an existing session record in the store.
It leaves the session state unchanged.
Sourcefn load<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<Option<SessionRecord>, LoadError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<Option<SessionRecord>, LoadError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Loads an existing session record from the store using the provided ID.
If a session with the given ID exists, it is returned. If the session
does not exist or has been invalidated (e.g., expired), None is
returned.
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), DeleteError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), DeleteError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Deletes a session record from the store using the provided ID.
If the session exists, it is removed from the store.
Sourcefn change_id<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
old_id: &'life1 SessionId,
new_id: &'life2 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), ChangeIdError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn change_id<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
old_id: &'life1 SessionId,
new_id: &'life2 SessionId,
) -> Pin<Box<dyn Future<Output = Result<(), ChangeIdError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Change the session id associated with an existing session record.
The server-side state is left unchanged.
Sourcefn delete_expired<'life0, 'async_trait>(
&'life0 self,
batch_size: Option<NonZeroUsize>,
) -> Pin<Box<dyn Future<Output = Result<usize, DeleteExpiredError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete_expired<'life0, 'async_trait>(
&'life0 self,
batch_size: Option<NonZeroUsize>,
) -> Pin<Box<dyn Future<Output = Result<usize, DeleteExpiredError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Deletes expired session records from the store.
If batch_size is provided, the query will delete at most batch_size expired sessions.
In either case, if successful, the method returns the number of expired sessions that
have been deleted.
§When should you delete in batches?
If there are a lot of expired sessions in the database, deleting them all at once can cause performance issues. By deleting in batches, you can limit the number of sessions deleted in a single query, reducing the impact.
§Do I need to call this method?
It depends on the storage backend you are using. Some backends (e.g. Redis) have built-in support for expiring keys, so you may not need to call this method at all.
If you’re adding support for a new backend that has built-in support for expiring keys,
you can simply return Ok(0) from this method.