Skip to content

InMemoryAttachmentStore

Namespace AgentPrism · Assembly AgentPrism.Core.dll

A store that keeps attachments in process memory.

public sealed class InMemoryAttachmentStore : IAttachmentStore

objectInMemoryAttachmentStore

IAttachmentStore

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

Use the persistent store from AgentPrism.PostgreSql in production. This implementation is for development and tests. All attachments are lost when the process restarts.

InMemoryAttachmentStore(IAttachmentStorage?)

Section titled “ InMemoryAttachmentStore(IAttachmentStorage?)”

Initializes a new in-memory attachment store.

public InMemoryAttachmentStore(IAttachmentStorage? storage = null)

storage IAttachmentStorage?

When supplied, content is stored here and this store keeps only metadata. When null, content is kept directly in memory.

DeleteAsync(string, Guid, CancellationToken)

Section titled “ DeleteAsync(string, Guid, CancellationToken)”

Deletes an attachment.

public ValueTask<bool> DeleteAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)

tenantId string

The tenant id.

id Guid

The attachment id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

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)

tenantId string

The tenant id.

sessionId string

The session id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<int>

The number of records deleted.

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)

tenantId string

The tenant id.

id Guid

The attachment id.

cancellationToken CancellationToken

The cancellation token.

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)

query AttachmentQuery

The filter.

cancellationToken CancellationToken

The cancellation token.

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)

tenantId string

The tenant id.

id Guid

The attachment id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Stream?>

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)

content AttachmentContent

The content and metadata to save.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AttachmentDescriptor>

The attachment record with its id and digest assigned.