Table of Contents

Interface ITokenCache

Namespace
Arc4u.OAuth2.Token
Assembly
Arc4u.OAuth2.dll

A store for the tokens of the current user.

public interface ITokenCache

Remarks

Each method accepts an optional optionsName: the name of the named TokenCacheOptions that selects the cache and the expiration to use. When it is null, the default TokenCacheOptions (registered by AddTokenCache) are used. Implementations that have a single store ignore it.

The methods are asynchronous because the store is usually a distributed cache (Redis, SQL Server): a call must not block a thread during the round trip.

Methods

DeleteItemAsync(string, string?, CancellationToken)

Delete a token based on its unique key.

ValueTask DeleteItemAsync(string key, string? optionsName = null, CancellationToken cancellationToken = default)

Parameters

key string

The unique key of the token.

optionsName string

The name of the TokenCacheOptions to use, or null for the default ones.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

ValueTask

A task that completes when the entry is removed.

GetAsync<T>(string, string?, CancellationToken)

Gets a value.

ValueTask<T?> GetAsync<T>(string key, string? optionsName = null, CancellationToken cancellationToken = default)

Parameters

key string

The unique key.

optionsName string

The name of the TokenCacheOptions to use, or null for the default ones.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

ValueTask<T>

The value, or the default of T when there is none.

Type Parameters

T

The type of the value.

PutAsync<T>(string, T, string?, CancellationToken)

Adds or replaces a value.

ValueTask PutAsync<T>(string key, T data, string? optionsName = null, CancellationToken cancellationToken = default)

Parameters

key string

The unique key.

data T

The value to store. A null value is ignored by some implementations.

optionsName string

The name of the TokenCacheOptions to use, or null for the default ones.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

ValueTask

A task that completes when the value is stored.

Type Parameters

T

The type of the value.