Package io.karatelabs.http
Class InMemorySessionStore
java.lang.Object
io.karatelabs.http.InMemorySessionStore
- All Implemented Interfaces:
SessionStore
In-memory implementation of SessionStore.
Thread-safe using ConcurrentHashMap with lazy expiry cleanup.
Suitable for testing and simple single-instance deployments.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all sessions from the store.create(int expirySeconds) Create a new session with the specified expiry time.voidDelete a session from the store.Retrieve a session by its ID.voidSave/update a session in the store.intsize()Get the current number of sessions in the store.
-
Constructor Details
-
InMemorySessionStore
public InMemorySessionStore()
-
-
Method Details
-
create
Description copied from interface:SessionStoreCreate a new session with the specified expiry time.- Specified by:
createin interfaceSessionStore- Parameters:
expirySeconds- number of seconds until the session expires- Returns:
- newly created session with unique ID
-
get
Description copied from interface:SessionStoreRetrieve a session by its ID.- Specified by:
getin interfaceSessionStore- Parameters:
id- the session ID- Returns:
- the session if found and not expired, null otherwise
-
save
Description copied from interface:SessionStoreSave/update a session in the store.- Specified by:
savein interfaceSessionStore- Parameters:
session- the session to save
-
delete
Description copied from interface:SessionStoreDelete a session from the store.- Specified by:
deletein interfaceSessionStore- 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.
-