Skip to content

Commit 994c2f8

Browse files
committed
Add ALWAYS_SAVE_AFTER_REQUEST persistence policy.
1 parent b2b5924 commit 994c2f8

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

README.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ With an persistent session storage there is going to be the distinct possibility
123123
Since each situation is different, the manager gives you several options which control the details of when/how sessions are persisted. Each of the following options may be selected by setting the `sessionPersistPolicies="PERSIST_POLICY_1,PERSIST_POLICY_2,.."` attributes in your manager declaration in Tomcat's context.xml. Unless noted otherwise, the various options are all combinable.
124124

125125
- `SAVE_ON_CHANGE`: every time `session.setAttribute()` or `session.removeAttribute()` is called the session will be saved. __Note:__ This feature cannot detect changes made to objects already stored in a specific session attribute. __Tradeoffs__: This option will degrade performance slightly as any change to the session will save the session synchronously to Redis.
126+
- `ALWAYS_SAVE_AFTER_REQUEST`: force saving after every request, regardless of whether or not the manager has detected changes to the session. This option is particularly useful if you make changes to objects already stored in a specific session attribute. __Tradeoff:__ This option make actually increase the liklihood of race conditions if not all of your requests change the session.
126127

127128
Possible Issues
128129
---------------

src/main/java/com/radiadesign/catalina/session/RedisSessionHandlerValve.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private void storeOrRemoveSession(Session session) {
3838
log.trace("Request with session completed, saving session " + session.getId());
3939
if (session.getSession() != null) {
4040
log.trace("HTTP Session present, saving " + session.getId());
41-
manager.save(session);
41+
manager.save(session, manager.getAlwaysSaveAfterRequest());
4242
} else {
4343
log.trace("No HTTP Session present, Not saving " + session.getId());
4444
}

src/main/java/com/radiadesign/catalina/session/RedisSessionManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public class RedisSessionManager extends ManagerBase implements Lifecycle {
3737

3838
enum SessionPersistPolicy {
3939
DEFAULT,
40-
SAVE_ON_CHANGE;
40+
SAVE_ON_CHANGE,
41+
ALWAYS_SAVE_AFTER_REQUEST;
4142

4243
static SessionPersistPolicy fromName(String name) {
4344
for (SessionPersistPolicy policy : SessionPersistPolicy.values()) {
@@ -152,6 +153,10 @@ public boolean getSaveOnChange() {
152153
return this.sessionPersistPoliciesSet.contains(SessionPersistPolicy.SAVE_ON_CHANGE);
153154
}
154155

156+
public boolean getAlwaysSaveAfterRequest() {
157+
return this.sessionPersistPoliciesSet.contains(SessionPersistPolicy.ALWAYS_SAVE_AFTER_REQUEST);
158+
}
159+
155160
public String getSentinels() {
156161
return sentinels;
157162
}

0 commit comments

Comments
 (0)