Class InMemoryDocumentStore
- Namespace
- IntentSharp.Documents
- Assembly
- IntentSharp.dll
An IDocumentStore held in process memory: for tests, samples and applications that load their documents in code. Everything it holds is lost when the process ends. It follows the whole store contract, versions, running versions, rejection, change tokens and state etags included, and is safe to use from several threads.
public sealed class InMemoryDocumentStore : IDocumentStore
- Inheritance
-
objectInMemoryDocumentStore
- Implements
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Constructors
- InMemoryDocumentStore()
Creates an empty store that stamps versions and state with the system clock.
- InMemoryDocumentStore(TimeProvider)
Creates an empty store that stamps versions and state with
timeProvider.
Methods
- ActivateAsync(DocumentId, long, CancellationToken)
Makes a stored version the document's running version, as a revert to an older version or the promotion of a version saved without activation. Activating the running version changes nothing and returns it.
- GetChangeToken(string)
A token that fires once when any document whose path starts with
prefix(compared ordinally) gets a new running version. Ask for a new token after it fires.
- GetHistoryAsync(DocumentId, CancellationToken)
Every stored version of a document, rejected ones included, in ascending sequence; nothing for a document that does not exist.
- ListAsync(string, CancellationToken)
The running versions of every document whose path starts with
prefix(compared ordinally), in path order; an empty prefix lists them all.
- MarkRejectedAsync(DocumentId, long, string, CancellationToken)
Marks a stored version rejected, with the reason: a version that failed validation, such as an external edit the library refused. The version stays in the history and can still be read by its sequence, but it is never activated. Marking a rejected version again replaces its reason.
- ReadAsync(DocumentId, long?, CancellationToken)
Reads a version of a document: the running version when
sequenceis null, otherwise the version with that sequence, rejected or not. Returns null when the document has no running version, or no version with that sequence.
- ReadStateAsync(string, CancellationToken)
Reads a state value; null when the key has never been written.
- SaveAsync(DocumentSave, CancellationToken)
Stores a new version of a document and, when Activate is true, makes it the running version. Returns the new version.
- TryCreateStateAsync(string, JsonNode, CancellationToken)
Creates a state value only when the key has none: of several writers, in one process or several, that create the same key at once, exactly one stores its value. Returns the entry as written, with its etag; null when the key already has a value, and then nothing was written. Read the key to see the value that is there.
- WriteStateAsync(string, JsonNode, string?, CancellationToken)
Writes a state value. With
expectedEtagnull the value is created or overwritten; otherwise it is written only when the key's current etag isexpectedEtag. Returns the entry as written, with its new etag. To create a value only when the key has none, call TryCreateStateAsync(string, JsonNode, CancellationToken).