Interface SessionCache

    • Method Detail

      • setSessionDataStore

        void setSessionDataStore​(SessionDataStore sds)
        A SessionDataStore that is the authoritative source of session information.
        Parameters:
        sds - the session data store
      • getEvictionPolicy

        int getEvictionPolicy()
      • setEvictionPolicy

        void setEvictionPolicy​(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()
      • isRemoveUnloadableSessions

        boolean isRemoveUnloadableSessions()
      • setRemoveUnloadableSessions

        void setRemoveUnloadableSessions​(boolean removeUnloadableSessions)
        If the data for a session exists but is unreadable, the SessionCache can instruct the SessionDataStore to delete it.
        Parameters:
        removeUnloadableSessions - whether or not SessionCache will delete session data that can not be loaded from the SessionDataStore
      • 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()
      • 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
      • get

        Session 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 SessionDataStore.
        Parameters:
        id - the session id
        Returns:
        the Session if one exists, null otherwise
        Throws:
        java.lang.Exception - if an error occurs
      • put

        void put​(java.lang.String id,
                 Session 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 SessionDataStore.
        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 SessionDataStore.
        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

        Session delete​(java.lang.String id)
                throws java.lang.Exception
        Remove a Session completely: from both this cache and the SessionDataStore.
        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
      • 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 SessionDataStore, 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​(Session session)
        Check a Session to see if it might be appropriate to evict or expire.
        Parameters:
        session - the session object
      • newSession

        Session newSession​(java.lang.String id,
                           long time,
                           long maxInactiveIntervalMS)
      • newSession

        Session newSession​(SessionData data)
        Re-materialize a Session that has previously existed.
        Parameters:
        data - the session data
        Returns:
        a Session object for the data supplied
      • getSessionsCurrent

        long getSessionsCurrent()
        Returns:
        the number of sessions in the cache
      • getSessionsMax

        long getSessionsMax()
        Returns:
        the max number of sessions in the cache
      • getSessionsTotal

        long getSessionsTotal()
        Returns a running total of sessions in the cache.
        Returns:
        a running total of sessions in the cache
      • resetStats

        void resetStats()
        Resets the running total session count in the cache.
      • clear

        void clear()