Package com.google.genkit.ai.session
Class InMemorySessionStore<S>
java.lang.Object
com.google.genkit.ai.session.InMemorySessionStore<S>
- Type Parameters:
S- the type of the custom session state
- All Implemented Interfaces:
SessionStore<S>
InMemorySessionStore is a simple in-memory implementation of SessionStore.
This implementation is suitable for:
- Development and testing
- Single-instance deployments
- Prototyping
Note: Sessions are lost when the application restarts. For production use cases requiring persistence, implement a database-backed SessionStore.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all sessions from the store.Deletes a session by its ID.Checks if a session exists.Retrieves a session by its ID.save(String sessionId, SessionData<S> sessionData) Saves session data.intsize()Returns the number of sessions currently stored.
-
Constructor Details
-
InMemorySessionStore
public InMemorySessionStore()Creates a new InMemorySessionStore.
-
-
Method Details
-
get
Description copied from interface:SessionStoreRetrieves a session by its ID.- Specified by:
getin interfaceSessionStore<S>- Parameters:
sessionId- the session ID- Returns:
- a CompletableFuture containing the session data, or null if not found
-
save
Description copied from interface:SessionStoreSaves session data.- Specified by:
savein interfaceSessionStore<S>- Parameters:
sessionId- the session IDsessionData- the session data to save- Returns:
- a CompletableFuture that completes when the save is done
-
delete
Description copied from interface:SessionStoreDeletes a session by its ID.- Specified by:
deletein interfaceSessionStore<S>- Parameters:
sessionId- the session ID- Returns:
- a CompletableFuture that completes when the deletion is done
-
exists
Description copied from interface:SessionStoreChecks if a session exists.- Specified by:
existsin interfaceSessionStore<S>- Parameters:
sessionId- the session ID- Returns:
- a CompletableFuture containing true if the session exists
-
size
public int size()Returns the number of sessions currently stored.- Returns:
- the session count
-
clear
public void clear()Clears all sessions from the store.
-