Skip to content

Commit

Permalink
Add ALWAYS_SAVE_AFTER_REQUEST persistence policy.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoleman committed Sep 29, 2014
1 parent b2b5924 commit 994c2f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ With an persistent session storage there is going to be the distinct possibility
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.

- `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.
- `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.

Possible Issues
---------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private void storeOrRemoveSession(Session session) {
log.trace("Request with session completed, saving session " + session.getId());
if (session.getSession() != null) {
log.trace("HTTP Session present, saving " + session.getId());
manager.save(session);
manager.save(session, manager.getAlwaysSaveAfterRequest());
} else {
log.trace("No HTTP Session present, Not saving " + session.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class RedisSessionManager extends ManagerBase implements Lifecycle {

enum SessionPersistPolicy {
DEFAULT,
SAVE_ON_CHANGE;
SAVE_ON_CHANGE,
ALWAYS_SAVE_AFTER_REQUEST;

static SessionPersistPolicy fromName(String name) {
for (SessionPersistPolicy policy : SessionPersistPolicy.values()) {
Expand Down Expand Up @@ -152,6 +153,10 @@ public boolean getSaveOnChange() {
return this.sessionPersistPoliciesSet.contains(SessionPersistPolicy.SAVE_ON_CHANGE);
}

public boolean getAlwaysSaveAfterRequest() {
return this.sessionPersistPoliciesSet.contains(SessionPersistPolicy.ALWAYS_SAVE_AFTER_REQUEST);
}

public String getSentinels() {
return sentinels;
}
Expand Down

0 comments on commit 994c2f8

Please sign in to comment.