Package dev.agenor.runtime.memory
Class InMemoryStore
java.lang.Object
dev.agenor.runtime.memory.InMemoryStore
- All Implemented Interfaces:
MemoryStore
In-memory implementation of MemoryStore.
This implementation:
- Stores memories in concurrent hash maps (thread-safe)
- Automatically cleans up expired entries
- Provides fast lookups and searches
- Does NOT persist to disk (volatile storage)
Suitable for:
- Development and testing
- Short-lived processes
- Caching layer
- Single-instance deployments
Example usage:
MemoryStore store = new InMemoryStore();
MemoryEntry entry = MemoryEntry.builder("Important fact")
.ownerId("my-agent")
.build();
store.store("fact-1", entry, MemoryScope.SHORT_TERM).join();
- Since:
- 0.6.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an InMemoryStore with default configuration.InMemoryStore(int maxEntriesPerScope, long cleanupIntervalSeconds) Creates an InMemoryStore with custom configuration. -
Method Summary
Modifier and TypeMethodDescriptionclear(MemoryScope scope) Clears all memory entries in the specified scope.delete(String key, MemoryScope scope) Deletes a memory entry.getStats()Gets statistics about memory usage.listKeys(MemoryScope scope) Lists all memory keys in the specified scope.retrieve(String key, MemoryScope scope) Retrieves a memory entry by key.search(MemoryQuery query) Searches for memory entries matching the query criteria.voidshutdown()Shuts down the cleanup executor.store(String key, MemoryEntry entry, MemoryScope scope) Stores a memory entry.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.agenor.core.memory.MemoryStore
exists, getStoreName
-
Constructor Details
-
InMemoryStore
public InMemoryStore()Creates an InMemoryStore with default configuration. -
InMemoryStore
public InMemoryStore(int maxEntriesPerScope, long cleanupIntervalSeconds) Creates an InMemoryStore with custom configuration.- Parameters:
maxEntriesPerScope- maximum entries per scope (0 = unlimited)cleanupIntervalSeconds- interval for cleanup task in seconds
-
-
Method Details
-
store
Description copied from interface:MemoryStoreStores a memory entry.If an entry with the same key and scope already exists, it will be replaced.
- Specified by:
storein interfaceMemoryStore- Parameters:
key- unique identifier for this memoryentry- the memory entry to storescope- the memory scope (SHORT_TERM or LONG_TERM)- Returns:
- a future that completes when the entry is stored
-
retrieve
Description copied from interface:MemoryStoreRetrieves a memory entry by key.Expired entries are automatically filtered out and return empty.
- Specified by:
retrievein interfaceMemoryStore- Parameters:
key- the memory keyscope- the memory scope to search in- Returns:
- a future containing the memory entry, or empty if not found
-
search
Description copied from interface:MemoryStoreSearches for memory entries matching the query criteria.Results are filtered by:
- Text content (if specified)
- Owner ID (if specified)
- Metadata filters (if specified)
- Non-expired entries only
Results may be returned in any order unless the implementation specifies otherwise.
- Specified by:
searchin interfaceMemoryStore- Parameters:
query- the search query parameters- Returns:
- a future containing matching memory entries (may be empty)
-
delete
Description copied from interface:MemoryStoreDeletes a memory entry.If the entry does not exist, this operation completes successfully without error (idempotent).
- Specified by:
deletein interfaceMemoryStore- Parameters:
key- the memory key to deletescope- the memory scope- Returns:
- a future that completes when the entry is deleted
-
clear
Description copied from interface:MemoryStoreClears all memory entries in the specified scope.Warning: This operation cannot be undone. Use with caution.
- Specified by:
clearin interfaceMemoryStore- Parameters:
scope- the memory scope to clear- Returns:
- a future that completes when all entries are cleared
-
listKeys
Description copied from interface:MemoryStoreLists all memory keys in the specified scope.This operation may be expensive for large memory stores. Consider using
MemoryStore.search(MemoryQuery)with pagination instead.- Specified by:
listKeysin interfaceMemoryStore- Parameters:
scope- the memory scope- Returns:
- a future containing all keys (may be empty)
-
getStats
Description copied from interface:MemoryStoreGets statistics about memory usage.Statistics may be cached and not reflect the absolute current state.
- Specified by:
getStatsin interfaceMemoryStore- Returns:
- memory usage statistics
-
shutdown
public void shutdown()Shuts down the cleanup executor. Should be called when the store is no longer needed.
-