InMemoryIdempotencyStore
AgentPrism.Core.dllA store that keeps idempotency records in process memory (first class).
public sealed class InMemoryIdempotencyStore : IIdempotencyStoreInheritance
Section titled “Inheritance”object ← InMemoryIdempotencyStore
Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”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.
Constructors
Section titled “Constructors”InMemoryIdempotencyStore()
Section titled “ InMemoryIdempotencyStore()”public InMemoryIdempotencyStore()Methods
Section titled “Methods”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)Parameters
Section titled “Parameters”tenantId string
The tenant identifier.
key string
The key.
response IdempotencyResponse
The response to store.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”tenantId string
The tenant identifier.
key string
The key.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”Remarks
Section titled “Remarks”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)Parameters
Section titled “Parameters”request IdempotencyRequest
The reservation request.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<IdempotencyReservation>
The reservation result.
Remarks
Section titled “Remarks”The reservation must be atomic: if two concurrent requests arrive with the same key, only one must get IdempotencyState.Reserved, the other IdempotencyState.InProgress.