pub struct InMemoryTaskStore { /* private fields */ }Expand description
In-memory TaskStore backed by a BTreeMap under a RwLock.
Suitable for testing and single-process deployments. Data is lost when the process exits.
Supports TTL-based eviction of terminal tasks and a maximum capacity limit to prevent unbounded memory growth.
§Eviction behavior
Eviction runs as a background task every N writes (configurable via
TaskStoreConfig::eviction_interval) and whenever the store exceeds
max_capacity. The eviction sweep is decoupled from the save() write
lock so that writers are not blocked during the O(n) cleanup. However,
if the system goes idle (no save() calls), completed tasks may persist
in memory longer than their TTL.
Operators should call run_eviction() periodically
(e.g. every 60 seconds via tokio::time::interval) to ensure timely
cleanup of terminal tasks during idle periods.
§Concurrency
For high-concurrency production deployments, consider SqliteTaskStore
which uses a connection pool and row-level locking. The in-memory store
uses a single RwLock and is optimized for testing and moderate load.
Implementations§
Source§impl InMemoryTaskStore
impl InMemoryTaskStore
Sourcepub async fn run_eviction(&self)
pub async fn run_eviction(&self)
Runs background eviction of expired and over-capacity entries.
Call this periodically (e.g. every 60 seconds) to clean up terminal
tasks that would otherwise persist until the next save() call.
Source§impl InMemoryTaskStore
impl InMemoryTaskStore
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty in-memory task store with default configuration.
Default: max 10,000 tasks, 1-hour TTL for terminal tasks.
Sourcepub fn with_config(config: TaskStoreConfig) -> Self
pub fn with_config(config: TaskStoreConfig) -> Self
Creates a new in-memory task store with custom configuration.
Trait Implementations§
Source§impl Debug for InMemoryTaskStore
impl Debug for InMemoryTaskStore
Source§impl Default for InMemoryTaskStore
impl Default for InMemoryTaskStore
Source§impl TaskStore for InMemoryTaskStore
impl TaskStore for InMemoryTaskStore
Source§fn save<'a>(
&'a self,
task: Task,
) -> Pin<Box<dyn Future<Output = A2aResult<()>> + Send + 'a>>
fn save<'a>( &'a self, task: Task, ) -> Pin<Box<dyn Future<Output = A2aResult<()>> + Send + 'a>>
Source§fn get<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = A2aResult<Option<Task>>> + Send + 'a>>
fn get<'a>( &'a self, id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = A2aResult<Option<Task>>> + Send + 'a>>
None if not found. Read moreSource§fn list<'a>(
&'a self,
params: &'a ListTasksParams,
) -> Pin<Box<dyn Future<Output = A2aResult<TaskListResponse>> + Send + 'a>>
fn list<'a>( &'a self, params: &'a ListTasksParams, ) -> Pin<Box<dyn Future<Output = A2aResult<TaskListResponse>> + Send + 'a>>
Source§fn insert_if_absent<'a>(
&'a self,
task: Task,
) -> Pin<Box<dyn Future<Output = A2aResult<bool>> + Send + 'a>>
fn insert_if_absent<'a>( &'a self, task: Task, ) -> Pin<Box<dyn Future<Output = A2aResult<bool>> + Send + 'a>>
Auto Trait Implementations§
impl !Freeze for InMemoryTaskStore
impl !RefUnwindSafe for InMemoryTaskStore
impl Send for InMemoryTaskStore
impl Sync for InMemoryTaskStore
impl Unpin for InMemoryTaskStore
impl UnsafeUnpin for InMemoryTaskStore
impl UnwindSafe for InMemoryTaskStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request