Interface IShortLivedStore
Stores the short-lived state that services keep between requests: the toolkit's sign-in codes, device links, passkey ceremonies and rate limit counts, and the state of an app's own multi-step flows. All the servers of a service must share one store.
Namespace: Singulink.Net.Http.Api.Service
Assembly: Singulink.Net.Http.Api.Service.dll
Syntax
public interface IShortLivedStore
Remarks
Values are opaque strings that expire after a lifetime. A key holds either a value or a counter, and a counter's value is its count as decimal text, so GetAsync(string, CancellationToken) reads counters too. Expired entries behave as if they did not exist.
Every operation must be atomic, also across servers: TryAddAsync(string, string, TimeSpan, CancellationToken) adds a value for a key once until it expires or is removed, TakeAsync(string, CancellationToken) returns a value at most once, and IncrementAsync(string, long, TimeSpan, CancellationToken) counts every increment. Implementations are registered as singletons.
The toolkit's own keys start with httpapi:, so apps use other prefixes for their keys. See ShortLivedStoreExtensions for adding values
under new random keys and for storing typed states.
The default implementation, MemoryShortLivedStore, keeps values in the memory of the process, so the servers of a service do not share them.
Methods
| Name | Description |
|---|---|
| GetAsync(string, CancellationToken) | Gets the value of a key, or returns null if the key has no value. The value of a counter is its count as decimal text. |
| IncrementAsync(string, long, TimeSpan, CancellationToken) | Adds an amount to the counter under a key and returns the new count. A key without a value counts from 0. Every increment sets the counter to expire after the lifetime, counted from the increment. |
| RemoveAsync(string, CancellationToken) | Removes the value of a key, if it has one. |
| TakeAsync(string, CancellationToken) | Gets and removes the value of a key, or returns null if the key has no value. A value is returned at most once, even when it is taken by concurrent calls. |
| TryAddAsync(string, string, TimeSpan, CancellationToken) | Adds a value under a key unless the key already has a value. |