View Source Charon.SessionStore.Behaviour behaviour (Charon v1.3.4)

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 session, with time-to-live ttl.

Link to this section Callbacks

Link to this callback

delete(session_id, user_id, config)

View Source
@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.

Link to this callback

delete_all(user_id, config)

View Source (optional)
@callback delete_all(user_id :: binary() | integer(), config :: Charon.Config.t()) ::
  :ok | {:error, binary()}

Delete all sessions for the user with id user_id.

Link to this callback

get(session_id, user_id, config)

View Source
@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.

Link to this callback

get_all(user_id, config)

View Source (optional)
@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.

Link to this callback

upsert(session, ttl, config)

View Source
@callback upsert(
  session :: Charon.Session.t(),
  ttl :: pos_integer(),
  config :: Charon.Config.t()
) :: :ok | {:error, binary()}

Insert or update 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.