View Source Charon.SessionStore behaviour (Charon v1.1.0-beta)
Behaviour definition of a persistent session store. The implementation is expected to handle cleanup of expired entries.
All three callbacks can use only a session ID, and ignore the user ID that is passed in as well, because a session ID is a unique 128-bits binary by itself.
However, not ignoring the user ID enables the usecase where all sessions for a user are fetched or deleted (the optional callbacks), for example, so there are benefits to storing sessions per user.
Link to this section Summary
Callbacks
Delete session with id session_id
for user with id user_id
.
Delete all sessions for the user with id user_id
.
Get session with id session_id
for user with id user_id
.
Get all sessions for the user with id user_id
.
Insert or update Elixir.Charon.Session session
, with time-to-live ttl
.
Link to this section Callbacks
@callback delete( session_id :: binary(), user_id :: binary() | integer(), config :: Charon.Config.t() ) :: :ok | {:error, binary()}
Delete session with id session_id
for user with id user_id
.
Implementations may choose to ignore user_id
, since session_id
is unique by itself.
@callback delete_all(user_id :: binary() | integer(), config :: Charon.Config.t()) :: :ok | {:error, binary()}
Delete all sessions for the user with id user_id
.
@callback get( session_id :: binary(), user_id :: binary() | integer(), config :: Charon.Config.t() ) :: Charon.Session.t() | nil | {:error, binary()}
Get session with id session_id
for user with id user_id
.
Implementations may choose to ignore user_id
, since session_id
is unique by itself.
@callback get_all(user_id :: binary() | integer(), config :: Charon.Config.t()) :: [Charon.Session.t()] | {:error, binary()}
Get all sessions for the user with id user_id
.
@callback upsert( session :: Charon.Session.t(), ttl :: pos_integer(), config :: Charon.Config.t() ) :: :ok | {:error, binary()}
Insert or update Elixir.Charon.Session session
, with time-to-live ttl
.
The session_id
and user_id
are taken from the session
struct.
Implementations may choose to ignore user_id
, since session_id
is unique by itself.