Skip to content

InMemoryIdempotencyStore

Namespace AgentPrism · Assembly AgentPrism.Core.dll

A store that keeps idempotency records in process memory (first class).

public sealed class InMemoryIdempotencyStore : IIdempotencyStore

objectInMemoryIdempotencyStore

IIdempotencyStore

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Its behavior contract matches SqlIdempotencyStore exactly and shared contract tests protect it. It is sufficient for a single-instance deployment. A multi-instance deployment needs a SQL provider because each instance keeps its own set of entries.

public InMemoryIdempotencyStore()

CompleteAsync(string, string, IdempotencyResponse, CancellationToken)

Section titled “ CompleteAsync(string, string, IdempotencyResponse, CancellationToken)”

Records the completed response and sets the key’s state to Completed.

public ValueTask CompleteAsync(string tenantId, string key, IdempotencyResponse response, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

key string

The key.

response IdempotencyResponse

The response to store.

cancellationToken CancellationToken

The cancellation token.

ValueTask

ReleaseAsync(string, string, CancellationToken)

Section titled “ ReleaseAsync(string, string, CancellationToken)”

Deletes the record after a failed request; a retry with the same key becomes free again.

public ValueTask ReleaseAsync(string tenantId, string key, CancellationToken cancellationToken = default)

tenantId string

The tenant identifier.

key string

The key.

cancellationToken CancellationToken

The cancellation token.

ValueTask

A failed run’s record is not kept. The purpose of idempotency is to make retries safe; keeping a failure would mean the client can never retry after a transient error.

ReserveAsync(IdempotencyRequest, CancellationToken)

Section titled “ ReserveAsync(IdempotencyRequest, CancellationToken)”

Tries to reserve the key as Reserved. If the key already exists, the existing record’s state is returned and no new record is OPENED.

public ValueTask<IdempotencyReservation> ReserveAsync(IdempotencyRequest request, CancellationToken cancellationToken = default)

request IdempotencyRequest

The reservation request.

cancellationToken CancellationToken

The cancellation token.

ValueTask<IdempotencyReservation>

The reservation result.

The reservation must be atomic: if two concurrent requests arrive with the same key, only one must get IdempotencyState.Reserved, the other IdempotencyState.InProgress.