Interface SessionCache
- All Known Implementing Classes:
AbstractSessionCache
,DefaultSessionCache
public interface SessionCache
An interface for managing a set of Session objects pertaining to a context in memory.
Created: 2017. 6. 24.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionAdd an entirely new session to the cache.checkExpiration
(Set<String> candidates) Check a list of session ids that belong to potentially expired sessions.boolean
checkInactiveSession
(ManagedSession session) Check a Session to see if it might be appropriate to evict or expire.void
cleanOrphans
(long time) Remove all unmanaged sessions that expired at or before the given time.boolean
Check to see if a Session is in the cache.Remove a Session completely: from both this cache and the SessionStore.boolean
Check to see if a session exists: WILL consult the SessionStore.Get an existing Session.int
int
int
boolean
boolean
boolean
boolean
void
refresh
(ManagedSession session) Refreshes the data of the session to be used.void
release
(ManagedSession session) Finish using a Session.renewSessionId
(String oldId, String newId) Change the id of a Session.void
setMaxActiveSessions
(int maxActiveSessions) Sets the maximum number of active sessions allowed in this session cache.void
setRemoveUnloadableSessions
(boolean removeUnloadableSessions) If the data for a session exists but is unreadable, the SessionCache can instruct the SessionStore to delete it.void
setSaveOnInactiveEviction
(boolean saveOnEvict) Whether a session that is about to be evicted should be saved before being evicted.
-
Field Details
-
NEVER_EVICT
static final int NEVER_EVICT- See Also:
-
EVICT_ON_SESSION_EXIT
static final int EVICT_ON_SESSION_EXIT- See Also:
-
EVICT_ON_INACTIVITY
static final int EVICT_ON_INACTIVITY- See Also:
-
-
Method Details
-
isClusterEnabled
boolean isClusterEnabled() -
getMaxActiveSessions
int getMaxActiveSessions() -
setMaxActiveSessions
void setMaxActiveSessions(int maxActiveSessions) Sets the maximum number of active sessions allowed in this session cache. The number of active sessions exceeds this limit, attempts to create new sessions will be rejected. If set to 0 (the default), there is no limit.- Parameters:
maxActiveSessions
- the maximum number of active sessions allowed in this session cache
-
getEvictionIdleSecs
int getEvictionIdleSecs()- Returns:
- the interval in seconds to evict inactive sessions from cache
-
getEvictionIdleSecsForNew
int getEvictionIdleSecsForNew() -
isSaveOnCreate
boolean isSaveOnCreate()- Returns:
- if true the newly created session will be saved immediately
-
isSaveOnInactiveEviction
boolean isSaveOnInactiveEviction()- Returns:
- true if the session should be saved before being evicted
-
setSaveOnInactiveEviction
void setSaveOnInactiveEviction(boolean saveOnEvict) Whether a session that is about to be evicted should be saved before being evicted.- Parameters:
saveOnEvict
- if true, save the session before eviction
-
isRemoveUnloadableSessions
boolean isRemoveUnloadableSessions()- Returns:
- if true unloadable session will be deleted
-
setRemoveUnloadableSessions
void setRemoveUnloadableSessions(boolean removeUnloadableSessions) If the data for a session exists but is unreadable, the SessionCache can instruct the SessionStore to delete it.- Parameters:
removeUnloadableSessions
- whether SessionCache will delete session data that can not be loaded from the SessionStore
-
get
Get an existing Session. If necessary, the cache will load the data for the session from the configured SessionStore.- Parameters:
id
- the session id- Returns:
- the Session if one exists, null otherwise
- Throws:
Exception
- if an error occurs
-
add
Add an entirely new session to the cache.- Parameters:
id
- the session idtime
- the timestamp of the session creationinactiveInterval
- the max inactive time in milliseconds- Throws:
Exception
-
refresh
Refreshes the data of the session to be used.- Parameters:
session
- the session object- Throws:
Exception
- if an error occurs
-
release
Finish using a Session. This is called by the SessionManager once a request is finished with a Session. SessionCache implementations may want to delay writing out Session contents until the last request exits a Session.- Parameters:
session
- the session object- Throws:
Exception
- if an error occurs
-
exists
Check to see if a session exists: WILL consult the SessionStore.- Parameters:
id
- the session id- Returns:
- true if the session exists; false otherwise
- Throws:
Exception
- if an error occurs
-
contains
Check to see if a Session is in the cache. Does NOT consult the SessionStore.- Parameters:
id
- the session id- Returns:
- true if a Session object matching the id is present in the cache; false otherwise
- Throws:
Exception
- if an error occurs
-
delete
Remove a Session completely: from both this cache and the SessionStore.- Parameters:
id
- the session id- Returns:
- the Session that was removed, null otherwise
- Throws:
Exception
- if an error occurs when deleting a session
-
renewSessionId
Change the id of a Session.- Parameters:
oldId
- the current session idnewId
- the new session id- Returns:
- the Session after changing its id
- Throws:
Exception
- if any error occurred
-
checkExpiration
Check a list of session ids that belong to potentially expired sessions. The Session in the cache should be checked, but also the SessionStore, as that is the authoritative source of all session information.- Parameters:
candidates
- the session ids to check- Returns:
- the set of session ids that have actually expired: this can be a superset of the original candidate list.
-
checkInactiveSession
Check a Session to see if it might be appropriate to evict or expire.- Parameters:
session
- the session object- Returns:
- true if evicted session, false otherwise
-
cleanOrphans
void cleanOrphans(long time) Remove all unmanaged sessions that expired at or before the given time.- Parameters:
time
- the time before which the sessions must have expired
-
getActiveSessions
- Returns:
- the identifiers of those sessions that are active on this node, excluding passivated sessions
-
getAllSessions
- Returns:
- the identifiers of all sessions, including both active and passive
-