HTTP API Toolkit HTTP API Toolkit
HTTP API Toolkit HTTP API Toolkit
DocFX + Singulink = ♥

Search Results for

    Class ShortLivedStoreExtensions

    Extension methods for IShortLivedStore: adding values under new random keys, storing typed states as JSON, and counting attempts in fixed windows.

    Inheritance
    object
    ShortLivedStoreExtensions
    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 permitLimit permits were already acquired in the current window. Windows start at fixed times on the clock (a one-hour window starts at every full hour), so every server that shares the store counts the same window.

    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 keyPrefix followed by the returned value, which the next step of a flow presents.

    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 keyPrefix followed by the returned value, which the next step of a flow presents.

    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 logger, if one is given.

    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 logger, if one is given. A state is returned at most once, even when it is taken by concurrent calls.

    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.

    © Singulink. All rights reserved.