only periodically save recently accessed sessions

Signed-off-by: nevafuse <nevafuse@gmail.com>
This commit is contained in:
nevafuse 2016-11-12 20:52:45 -05:00 committed by nevafuse
parent 3b36b13d31
commit 236571eaee
1 changed files with 8 additions and 1 deletions

View File

@ -51,6 +51,12 @@ public class HashedSession extends MemSession
* data stored in the session that is not serializable. */ * data stored in the session that is not serializable. */
private transient boolean _saveFailed = false; private transient boolean _saveFailed = false;
/**
* Last time session was saved to prevent periodic saves to sessions
* that have not changed
*/
private transient long _lastSaved = 0;
/** /**
* True if an attempt has been made to de-idle a session and it failed. Once * True if an attempt has been made to de-idle a session and it failed. Once
* true, the session will not be attempted to be de-idled again. * true, the session will not be attempted to be de-idled again.
@ -145,7 +151,7 @@ public class HashedSession extends MemSession
throws Exception throws Exception
{ {
File file = null; File file = null;
if (!_saveFailed && _hashSessionManager._storeDir != null) if (!_saveFailed && _hashSessionManager._storeDir != null && _lastSaved < getAccessed())
{ {
file = new File(_hashSessionManager._storeDir, super.getId()); file = new File(_hashSessionManager._storeDir, super.getId());
if (file.exists()) if (file.exists())
@ -155,6 +161,7 @@ public class HashedSession extends MemSession
try(FileOutputStream fos = new FileOutputStream(file,false)) try(FileOutputStream fos = new FileOutputStream(file,false))
{ {
_lastSaved = System.currentTimeMillis();
save(fos); save(fos);
} }
catch (Exception e) catch (Exception e)