Class InMemoryMappingStore
- Namespace
- IntentSharp.Mapping
- Assembly
- IntentSharp.dll
A mapping store in this process's memory: the rows and the replacement cap are lost when the process ends and are not shared with other processes. It holds at most a set number of keys; storing a new key in a full store removes the key used least recently, with every revision of it and its replacement cap. Rows are copied in and out, so a row a caller holds never changes the stored one. Thread-safe.
public sealed class InMemoryMappingStore : IMappingStore
- Inheritance
-
objectInMemoryMappingStore
- Implements
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Constructors
- InMemoryMappingStore(int)
Creates an empty store that holds at most
capacitykeys, with the system clock for the replacement cap's windows.
- InMemoryMappingStore(int, TimeProvider)
Creates an empty store that holds at most
capacitykeys, withtimeProviderfor the replacement cap's windows and the retirement times.
Methods
- ActivateAsync(string, string, int, MappingRetiredReason, CancellationToken)
In one transaction: retires the active revision of the key, if there is one, with
reasonand makes the pendingrevisionactive. Returns the active row.
- AddIfAbsentAsync(CompiledMapping, CancellationToken)
First writer wins: when the key has no active revision, stores
mappingas the next revision (1 for a new key) with the status Active. Returns the active row: this one, or the one another writer stored first.
- AddPendingAsync(CompiledMapping, CancellationToken)
Stores
pendingas the next revision with the status Pending and leaves the active revision as it is, for a replacement held until someone activates it. Returns the row as stored.
- GetActiveAsync(string, string, CancellationToken)
The active revision of a key, or null when the key has none. A retired or pending revision is never returned.
- ListAsync(string, CancellationToken)
Every revision of every key in the namespace, retired and pending ones included, ordered by key (ordinal) and then revision.
- ReplaceAsync(CompiledMapping, MappingRetiredReason, CompiledMapping, CancellationToken)
In one transaction: retires
retiringwithreasononly if that revision is still active, and then storesreplacementas the next revision with the status Active. When another writer replacedretiringfirst, nothing is written and that writer's row is returned; when the key has no active revision at all,replacementis stored as the active one. Returns the active row.
- RetireAsync(string, string, int, MappingRetiredReason, CancellationToken)
Retires an active or pending revision with
reason, for example a stored row the library refused. Returns true when the revision was active or pending and is now retired, false when it does not exist or was retired already.
- TryTakeRecompileAsync(string, string, int, TimeSpan, CancellationToken)
The persisted per-key cap on replacements, shared by every process on the store: takes one of
limitslots in the current window of lengthwindow, which starts at the first slot taken after the previous window ended. Returns true when a slot was taken, false when the window's slots are used up orlimitis 0 or less.