diff --git a/src/java/com/granicus/grails/plugins/cookiesession/SerializableSession.java b/src/java/com/granicus/grails/plugins/cookiesession/SerializableSession.java index 3785ebd..6279797 100644 --- a/src/java/com/granicus/grails/plugins/cookiesession/SerializableSession.java +++ b/src/java/com/granicus/grails/plugins/cookiesession/SerializableSession.java @@ -63,6 +63,7 @@ public boolean hasMoreElements() { private HashMap attributes; private Boolean isValid = true; + private Boolean isDirty = false; transient private ServletContext servletContext; transient private boolean newSession; transient private int maxInactiveInterval; @@ -166,12 +167,24 @@ public void removeValue(String name){ public void invalidate(){ isValid = false; + isDirty = true; } protected void setIsNewSession( boolean isNewSession ){ this.newSession = isNewSession; } + public boolean isNew(){ return ( this.newSession ); } + + protected void setIsDirty(boolean isDirty) + { + this.isDirty = isDirty; + } + + protected boolean getIsDirty() + { + return this.isDirty; + } } diff --git a/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryRequestWrapper.java b/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryRequestWrapper.java index ea72dbd..0481494 100644 --- a/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryRequestWrapper.java +++ b/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryRequestWrapper.java @@ -56,6 +56,12 @@ public void restoreSession() { // - assign the servlet context session = sessionRepository.restoreSession( this ); + + // we just loaded so we can't be dirty + if (session != null) + { + session.setIsDirty(false); + } if( sessionPersistenceListeners != null ){ // call sessionPersistenceListeners diff --git a/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryResponseWrapper.java b/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryResponseWrapper.java index 042327d..1ea041f 100644 --- a/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryResponseWrapper.java +++ b/src/java/com/granicus/grails/plugins/cookiesession/SessionRepositoryResponseWrapper.java @@ -35,7 +35,6 @@ public class SessionRepositoryResponseWrapper extends HttpServletResponseWrapper private String sessionId = "simplesession"; private SessionRepository sessionRepository; private SessionRepositoryRequestWrapper request; - private boolean sessionSaved = false; private boolean enforceSession = false; private ArrayList sessionPersistenceListeners; @@ -63,11 +62,6 @@ public void saveSession(){ return; } - if( sessionSaved == true ){ - if( log.isTraceEnabled() ){ log.trace("session is already saved, not attempting to save again."); } - return; - } - SerializableSession session = (SerializableSession) request.getSession(this.enforceSession); if( session == null ){ @@ -75,8 +69,10 @@ public void saveSession(){ return; } - // flag the session as saved. - sessionSaved = true; + if(session.getIsDirty() == false ){ + if( log.isTraceEnabled() ){ log.trace("session is not dirty, not saving."); } + return; + } if( log.isTraceEnabled() ){ log.trace("calling session repository to save session."); } @@ -93,6 +89,7 @@ public void saveSession(){ } sessionRepository.saveSession(session,this); + session.setIsDirty(false); } @Override