Spring Session有两个枚举,一个叫 SaveMode
和一个叫 FlushMode
参考文档中没有提到SaveMode和Flush模式。javadoc的描述听起来非常相似。
保存模式(SaveMode)
/**
* Supported modes of tracking and saving session changes to session store.
*
* @author Rob Winch
* @author Vedran Pavic
* @since 2.2.0
*/
public enum SaveMode {
/**
* Save only changes made to session, for instance using
* {@link Session#setAttribute(String, Object)}. In highly concurrent environments,
* this mode minimizes the risk of attributes being overwritten during processing of
* parallel requests.
*/
ON_SET_ATTRIBUTE,
/**
* Same as {@link #ON_SET_ATTRIBUTE} with addition of saving attributes that have been
* read using {@link Session#getAttribute(String)}.
*/
ON_GET_ATTRIBUTE,
/**
* Always save all session attributes, regardless of the interaction with the session.
* In highly concurrent environments, this mode increases the risk of attributes being
* overwritten during processing of parallel requests.
*/
ALWAYS
}
冲洗模式
/**
* Supported modes of writing the session to session store.
*
* @author Rob Winch
* @author Vedran Pavic
* @since 2.2.0
*/
public enum FlushMode {
/**
* Only writes to session store when {@link SessionRepository#save(Session)} is
* invoked. In a web environment this is typically done as soon as the HTTP response
* is committed.
*/
ON_SAVE,
/**
* Writes to session store as soon as possible. For example
* {@link SessionRepository#createSession()} will write the session to session store.
* Another example is that setting an attribute using
* {@link Session#setAttribute(String, Object)} will also write to session store
* immediately.
*/
IMMEDIATE
}