InMemoryAttachmentStore
AgentPrism.Core.dllA store that keeps attachments in process memory.
public sealed class InMemoryAttachmentStore : IAttachmentStoreInheritance
Section titled “Inheritance”object ← InMemoryAttachmentStore
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”Use the persistent store from AgentPrism.PostgreSql in production.
This implementation is for development and tests. All attachments are lost
when the process restarts.
Constructors
Section titled “Constructors”InMemoryAttachmentStore(IAttachmentStorage?)
Section titled “ InMemoryAttachmentStore(IAttachmentStorage?)”Initializes a new in-memory attachment store.
public InMemoryAttachmentStore(IAttachmentStorage? storage = null)Parameters
Section titled “Parameters”storage IAttachmentStorage?
When supplied, content is stored here and this store keeps only metadata. When null, content is kept directly in memory.
Methods
Section titled “Methods”DeleteAsync(string, Guid, CancellationToken)
Section titled “ DeleteAsync(string, Guid, CancellationToken)”Deletes an attachment.
public ValueTask<bool> DeleteAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”tenantId string
The tenant id.
id Guid
The attachment id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”true when a record was deleted.
DeleteBySessionAsync(string, string, CancellationToken)
Section titled “ DeleteBySessionAsync(string, string, CancellationToken)”Deletes every attachment of a session.
public ValueTask<int> DeleteBySessionAsync(string tenantId, string sessionId, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”tenantId string
The tenant id.
sessionId string
The session id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”The number of records deleted.
Remarks
Section titled “Remarks”It is called when a session is deleted; it keeps orphaned attachments from piling up.
GetAsync(string, Guid, CancellationToken)
Section titled “ GetAsync(string, Guid, CancellationToken)”Reads the metadata of a single attachment.
public ValueTask<AttachmentDescriptor?> GetAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”tenantId string
The tenant id.
id Guid
The attachment id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<AttachmentDescriptor?>
The record, or null when it does not exist or belongs to another tenant.
ListAsync(AttachmentQuery, CancellationToken)
Section titled “ ListAsync(AttachmentQuery, CancellationToken)”Lists the attachments through a filter.
public ValueTask<IReadOnlyList<AttachmentDescriptor>> ListAsync(AttachmentQuery query, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”query AttachmentQuery
The filter.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<IReadOnlyList<AttachmentDescriptor>>
The records ordered from newest to oldest.
OpenReadAsync(string, Guid, CancellationToken)
Section titled “ OpenReadAsync(string, Guid, CancellationToken)”Opens the raw content of an attachment as a stream.
public ValueTask<Stream?> OpenReadAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”tenantId string
The tenant id.
id Guid
The attachment id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”A readable stream, or null when the record does not exist or belongs to another tenant.
SaveAsync(AttachmentContent, CancellationToken)
Section titled “ SaveAsync(AttachmentContent, CancellationToken)”Saves a new attachment.
public ValueTask<AttachmentDescriptor> SaveAsync(AttachmentContent content, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”content AttachmentContent
The content and metadata to save.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<AttachmentDescriptor>
The attachment record with its id and digest assigned.