Class ShortLivedStoreExtensions
Extension methods for IShortLivedStore: adding values under new random keys, storing typed states as JSON, and counting attempts in fixed windows.
Namespace: Singulink.Net.Http.Api.Service
Assembly: Singulink.Net.Http.Api.Service.dll
Syntax
public static class ShortLivedStoreExtensions
Remarks
A state is kept under a key made of a prefix, which keeps the states of one flow apart from all others (for example "myapp:setup-ticket:"), and an
ID within it: a new random one from AddAsync<T>(IShortLivedStore, string, T, JsonTypeInfo<T>, TimeSpan, CancellationToken), or one of the
app's choosing. IsWellFormed(string?) tells whether a value has the form of a random one.
The typed methods take the JsonTypeInfo<T> of the state, typically from a source-generated JsonSerializerContext, so they work in
trimmed and AOT-compiled services. A stored value that cannot be read as the state, for example one stored by an earlier version of the service during
a rolling deployment, is treated as missing and logged to the logger given to the method, if any.
AcquirePermitAsync(IShortLivedStore, string, string, int, TimeSpan, TimeProvider, CancellationToken) counts attempts at something, such as sending emails to an address, in fixed windows, so that a limit holds across all the servers that share the store.
Methods
| Name | Description |
|---|---|
| AcquirePermitAsync(IShortLivedStore, string, string, int, TimeSpan, TimeProvider, CancellationToken) | Acquires a permit from a fixed window count, unless |
| AddAsync(IShortLivedStore, string, string, TimeSpan, CancellationToken) | Adds a value under a new random key and returns the random part of the key. The value is stored under |
| AddAsync<T>(IShortLivedStore, string, T, JsonTypeInfo<T>, TimeSpan, CancellationToken) | Adds a state, as JSON, under a new random key and returns the random part of the key. The state is stored under |
| GetAsync<T>(IShortLivedStore, string, string, JsonTypeInfo<T>, ILogger?, CancellationToken) | Gets a state, or returns null if it does not exist or cannot be read as the state, which is logged as a warning to
|
| RemoveAsync(IShortLivedStore, string, string, CancellationToken) | Removes a state, if it exists. |
| TakeAsync<T>(IShortLivedStore, string, string, JsonTypeInfo<T>, ILogger?, CancellationToken) | Gets and removes a state, or returns null if it does not exist or cannot be read as the state, which is logged as a warning to
|
| TryAddAsync<T>(IShortLivedStore, string, string, T, JsonTypeInfo<T>, TimeSpan, CancellationToken) | Adds a state, as JSON, under an ID of the app's choosing unless the key already has a value. |