My question is regarding how Hazelcast removes expired sessions from the underlying map.
I am running a large Java web application on Tomcat which uses cookie based sessions. Requests go through Hazelcast's WebFilter. WebFilter is configured to connect to an external Hazelcast cluster and store sessions in a map. Here's a subset of the web.xml filter configuration.
<init-param>
<param-name>use-client</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>map-name</param-name>
<param-value>SessionMap</param-value>
</init-param>
In web.xml, my session-timeout is set to 120 (i.e. 2 hours). The Hazelcast map, named SessionMap, has a TTL of 24 hours. The thinking here is that we want to end sessions that are inactive for 2 hours but if someone is continuously using the application we want to let the session to continue for a max of 24 hours.
The problem is that if I leave a session idle, Tomcat will terminate the session after 2 hours but the session will still remain in the Hazelcast map (SessionMap) until the TTL. Is there any way to have Hazelcast automatically remove sessions from the underlying map when they are expired in Tomcat?
The application can have a large number of sessions and very few will ever remain active for the full 24 hours so we don't want to leave sessions in Hazelcast's memory that are already expired.
I am using Hazelcast 3.8.
EDIT In Hazelcast documentation (http://docs.hazelcast.org/docs/3.5/manual/html/websessionreplication.html), it says:
Hazelcast automatically removes sessions from the cluster if the sessions are expired on the Web Container. This removal is done by com.hazelcast.web.SessionListener, which is an implementation of javax.servlet.http.HttpSessionListener.
Does this only apply if the Hazelcast cluster being used to store sessions is embedded? If so, is there a solution to achieve similar behavior when the sessions are stored in an external cluster?