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.

    • Method Detail

      • isClusterEnabled

        boolean isClusterEnabled()
      • getMaxSessions

        int getMaxSessions()
      • setMaxSessions

        void setMaxSessions​(int maxSessions)
        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:
        maxSessions - the maximum number of active sessions allowed in this session cache
      • getEvictionIdleSecs

        int getEvictionIdleSecs()
      • setEvictionIdleSecs

        void setEvictionIdleSecs​(int policy)
        Sessions in this cache can be:
        • never evicted
        • evicted once the last request exits
        • evicted after a configurable period of inactivity
        Parameters:
        policy - -1 is never evict; 0 is evict-on-exit; and any other positive value is the time in seconds that a session can be idle before it can be evicted.
      • isSaveOnCreate

        boolean isSaveOnCreate()
        Returns:
        if true the newly created session will be saved immediately
      • setSaveOnCreate

        void setSaveOnCreate​(boolean saveOnCreate)
        Whether or not a session that is newly created should be immediately saved. If false, a session that is created and invalidated within a single request is never persisted.
        Parameters:
        saveOnCreate - if true, immediately save the newly created session
      • isSaveOnInactiveEviction

        boolean isSaveOnInactiveEviction()
        Returns:
        true if the session should be saved before being evicted
      • setSaveOnInactiveEviction

        void setSaveOnInactiveEviction​(boolean saveOnEvict)
        Whether or not a 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 or not SessionCache will delete session data that can not be loaded from the SessionStore
      • get

        DefaultSession get​(java.lang.String id)
                    throws java.lang.Exception
        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:
        java.lang.Exception - if an error occurs
      • add

        DefaultSession add​(java.lang.String id,
                           long time,
                           long maxInactiveInterval)
                    throws java.lang.Exception
        Add an entirely new session to the cache.
        Parameters:
        id - the session id
        time - the timestamp of the session creation
        maxInactiveInterval - the max inactive time in milliseconds
        Throws:
        java.lang.Exception
      • release

        void release​(java.lang.String id,
                     DefaultSession session)
              throws java.lang.Exception
        Finish using a Session. This is called by the SessionHandler 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:
        id - the session id
        session - the session object
        Throws:
        java.lang.Exception - if an error occurs
      • exists

        boolean exists​(java.lang.String id)
                throws java.lang.Exception
        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:
        java.lang.Exception - if an error occurs
      • contains

        boolean contains​(java.lang.String id)
                  throws java.lang.Exception
        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:
        java.lang.Exception - if an error occurs
      • delete

        DefaultSession delete​(java.lang.String id)
                       throws java.lang.Exception
        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:
        java.lang.Exception - if an error occurs when deleting a session
      • renewSessionId

        DefaultSession renewSessionId​(java.lang.String oldId,
                                      java.lang.String newId)
                               throws java.lang.Exception
        Change the id of a Session.
        Parameters:
        oldId - the current session id
        newId - the new session id
        Returns:
        the Session after changing its id
        Throws:
        java.lang.Exception - if any error occurred
      • checkExpiration

        java.util.Set<java.lang.String> checkExpiration​(java.util.Set<java.lang.String> candidates)
        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

        void checkInactiveSession​(DefaultSession session)
        Check a Session to see if it might be appropriate to evict or expire.
        Parameters:
        session - the session object
      • getAllSessions

        java.util.Set<java.lang.String> getAllSessions()
      • getActiveSessionCount

        long getActiveSessionCount()
        Returns:
        the number of sessions in the cache
      • getHighestSessionCount

        long getHighestSessionCount()
        Returns:
        the max number of sessions in the cache
      • getCreatedSessionCount

        long getCreatedSessionCount()
        Returns:
        a running total of sessions in the cache
      • getExpiredSessionCount

        long getExpiredSessionCount()
      • getRejectedSessionCount

        long getRejectedSessionCount()
      • resetStatistics

        void resetStatistics()
        Resets the running total session count in the cache.
      • destroy

        void destroy()