Class MicroSessionCacheService

java.lang.Object
overit.geocall.rs.MicroSessionCacheService

public class MicroSessionCacheService extends Object
MicroSessionCacheService is a class that provides a cache for MicroSession objects. It uses an ExpiringMap to store the MicroSession objects with an expiration time. The cache allows retrieval, insertion, and removal of MicroSessions.

MicroSessionCacheService is a singleton class, meaning there is only one instance of it throughout the application. It can be accessed using the getInstance() method. The MicroSessionCacheService instance holds the ExpiringMap cache and a Clock object to manage expiration logic.

Expiration of MicroSessions is handled through the ExpiringMap. It periodically removes expired MicroSessions using a background cleaning process executed by a scheduled executor service.

Usage:


     // Retrieve the MicroSessionCacheService instance
     MicroSessionCacheService sessionCache = MicroSessionCacheService.getInstance();

     // Get a MicroSession from the cache
     MicroSession session = sessionCache.get("sessionId");

     // Put a MicroSession into the cache
     sessionCache.put(session);

     // Remove a MicroSession from the cache
     sessionCache.remove(session);
 
  • Method Details

    • getInstance

      public static MicroSessionCacheService getInstance()
      getInstance retrieves the singleton instance of MicroSessionCacheService.
      Returns:
      the singleton instance of MicroSessionCacheService
    • get

      public MicroSession get(String sessionId)
      Retrieves a MicroSession from the cache using the given session ID.
      Parameters:
      sessionId - the session ID used to retrieve the MicroSession
      Returns:
      the MicroSession associated with the session ID, or null if no mapping is found
    • put

      public void put(MicroSession microSession)
      Stores a MicroSession in the cache with an expiration time based on the session latency of the associated Identity.
      Parameters:
      microSession - the MicroSession to be stored in the cache
    • put

      public void put(MicroSession microSession, long expiration)
      Stores a MicroSession in the cache with an expiration time.
      Parameters:
      microSession - the MicroSession to be stored in the cache
      expiration - the expiration of the cache in ms
    • remove

      public void remove(String microSessionId)
      Removes the MicroSession from the cache.
      Parameters:
      microSessionId - the MicroSession identifier to be removed from the cache