Class InMemorySessionStore

java.lang.Object
io.karatelabs.http.InMemorySessionStore
All Implemented Interfaces:
SessionStore

public class InMemorySessionStore extends Object implements SessionStore
In-memory implementation of SessionStore. Thread-safe using ConcurrentHashMap with lazy expiry cleanup. Suitable for testing and simple single-instance deployments.
  • Constructor Details

    • InMemorySessionStore

      public InMemorySessionStore()
  • Method Details

    • create

      public Session create(int expirySeconds)
      Description copied from interface: SessionStore
      Create a new session with the specified expiry time.
      Specified by:
      create in interface SessionStore
      Parameters:
      expirySeconds - number of seconds until the session expires
      Returns:
      newly created session with unique ID
    • get

      public Session get(String id)
      Description copied from interface: SessionStore
      Retrieve a session by its ID.
      Specified by:
      get in interface SessionStore
      Parameters:
      id - the session ID
      Returns:
      the session if found and not expired, null otherwise
    • save

      public void save(Session session)
      Description copied from interface: SessionStore
      Save/update a session in the store.
      Specified by:
      save in interface SessionStore
      Parameters:
      session - the session to save
    • delete

      public void delete(String id)
      Description copied from interface: SessionStore
      Delete a session from the store.
      Specified by:
      delete in interface SessionStore
      Parameters:
      id - the session ID to delete
    • size

      public int size()
      Get the current number of sessions in the store. Useful for testing and monitoring.
    • clear

      public void clear()
      Clear all sessions from the store. Useful for testing.