Interface SessionDataSaveStrategy<A>

Type Parameters:
A - the session data type
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface SessionDataSaveStrategy<A>

A strategy for determining whether resolved session data shall be saved when saving a session.

This can be used by specific SessionStore that wants to optimize communications with an underlying data store. Since the session instance holds an opaque session data instance which may or may not be updated after being returned by Session.getData(), a session store needs such external strategy to determine whether data should be saved or not. The session data save strategy shall have the knowledge of the actual session data type and therefore be able to determine changes in the data providing it holds some state.

Since:
1.13
Author:
Jeremy Kuhn
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    getAndSetSaveState(A sessionData, boolean saveNeeded)
    Determines whether the specified session data should be saved and set the new save state into the data.
    Returns a strategy where session data are saved whenever they are resolved.
    Returns a strategy where session data are only saved when it was explicitly set in the session.
  • Method Details

    • onGet

      static <A> SessionDataSaveStrategy<A> onGet()

      Returns a strategy where session data are saved whenever they are resolved.

      This is the default strategy for stateful session data stored in the backend. It should be suitable for most usage, but it is not optimal and using the onSetOnly() strategy or providing a more specific implementation when performance is at stake is recommended.

      This strategy is not suited for stateless data which are stored in the session id (see JWTSession) as it may lead to multiple session id refresh during the processing of a single request and as such it shall never be used in that particular case.

      Type Parameters:
      A - the session data type
      Returns:
      a strategy that advices to save session data on get (i.e. always)
    • onSetOnly

      static <A> SessionDataSaveStrategy<A> onSetOnly()

      Returns a strategy where session data are only saved when it was explicitly set in the session.

      This is the default behaviour for stateless session data stored in the session id in the frontend (see JWTSession).

      Type Parameters:
      A - the session data type
      Returns:
      a strategy that advices to save session data on set only
    • getAndSetSaveState

      boolean getAndSetSaveState(A sessionData, boolean saveNeeded)

      Determines whether the specified session data should be saved and set the new save state into the data.

      This is typically invoked in a session store implementation right before saving a session with the saveNeeded set to false to prevent duplicate savings.

      Parameters:
      sessionData - the session data to save
      saveNeeded - the new save state to store in the session data
      Returns:
      true if the data should be saved, false otherwise