From aac6ee85f999398f6c3ba9203d115bf9406116b3 Mon Sep 17 00:00:00 2001 From: Ranjith Manickam Date: Tue, 4 Dec 2018 03:17:42 +0530 Subject: [PATCH] Bug fixes and added redis sentinel supportability changes. --- .../data/cache/impl/StandardDataCache.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/tomcat/request/session/data/cache/impl/StandardDataCache.java b/src/main/java/tomcat/request/session/data/cache/impl/StandardDataCache.java index a5f26cd..bfa25c4 100644 --- a/src/main/java/tomcat/request/session/data/cache/impl/StandardDataCache.java +++ b/src/main/java/tomcat/request/session/data/cache/impl/StandardDataCache.java @@ -108,7 +108,7 @@ public class StandardDataCache extends RedisCache { /** Session data. */ private class SessionData implements Serializable { private byte[] value; - private Date lastAccessedOn; + private long lastAccessedOn; SessionData(byte[] value) { this.value = value; @@ -116,7 +116,7 @@ public class StandardDataCache extends RedisCache { } void updatedLastAccessedOn() { - this.lastAccessedOn = new Date(); + this.lastAccessedOn = new Date().getTime(); } byte[] getValue() { @@ -124,7 +124,7 @@ public class StandardDataCache extends RedisCache { return this.value; } - Date getLastAccessedOn() { + long getLastAccessedOn() { return this.lastAccessedOn; } } @@ -189,12 +189,12 @@ public class StandardDataCache extends RedisCache { private final Log LOGGER = LogFactory.getLog(SessionDataExpiryThread.class); - private final int sessionExpiryTime; + private final long expiry; private final Map sessionData; SessionDataExpiryThread(Map sessionData, int sessionExpiryTime) { this.sessionData = sessionData; - this.sessionExpiryTime = (sessionExpiryTime + 60) / 60; + this.expiry = TimeUnit.SECONDS.toMillis(sessionExpiryTime + 60); new Thread(this).start(); } @@ -208,10 +208,8 @@ public class StandardDataCache extends RedisCache { continue; } - long diff = new Date().getTime() - data.getLastAccessedOn().getTime(); - long diffMinutes = diff / (60 * 1000) % 60; - - if (diffMinutes > this.sessionExpiryTime) { + long difference = new Date().getTime() - data.getLastAccessedOn(); + if (difference >= this.expiry) { this.sessionData.remove(key); } }