Table of Contents

Class ApplicationCache

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

An ITokenCache that stores the tokens in the cache designated by CacheName (the default cache when the name is empty or unknown). The keys are lower-cased and suffixed with _TokenCache.

[Export(typeof(ITokenCache))]
[Shared]
public class ApplicationCache : ITokenCache
Inheritance
ApplicationCache
Implements
Inherited Members

Remarks

The cache and the MaxTime are given by the TokenCacheResolver: the optionsName given to each method selects the named options (for example the key of an Authentication:ClientTokens entry), and null selects the default ones.

A name is used only when options are registered under it (see TokenCacheResolver): by AddNamedTokenCache, AddSharedTokenCache, AddClientTokens, AddOnBehalfOf or services.Configure<TokenCacheOptions>(name, …). Any other name, for example a typo, uses the default options and a warning is logged once.

Constructors

ApplicationCache(ILogger, TokenCacheResolver)

An ITokenCache that stores the tokens in the cache designated by CacheName (the default cache when the name is empty or unknown). The keys are lower-cased and suffixed with _TokenCache.

public ApplicationCache(ILogger logger, TokenCacheResolver resolver)

Parameters

logger ILogger

The logger.

resolver TokenCacheResolver

Resolves the cache and the maximum time of the default or named token cache options.

Remarks

The cache and the MaxTime are given by the TokenCacheResolver: the optionsName given to each method selects the named options (for example the key of an Authentication:ClientTokens entry), and null selects the default ones.

A name is used only when options are registered under it (see TokenCacheResolver): by AddNamedTokenCache, AddSharedTokenCache, AddClientTokens, AddOnBehalfOf or services.Configure<TokenCacheOptions>(name, …). Any other name, for example a typo, uses the default options and a warning is logged once.

Methods

DeleteItemAsync(string, string?, CancellationToken)

Removes the entry stored for the key. The claims cached by the claims filler are stored under another key and are not removed.

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

Parameters

key string

The 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.

GetAll()

Not supported.

public IEnumerable<byte[]> GetAll()

Returns

IEnumerable<byte[]>

Never returns.

Exceptions

NotImplementedException

Always thrown.

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

Gets a value.

public 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.

public 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.

Remarks

The entry is evicted after MaxTime. A TokenInfo is evicted at its ExpiresOnUtc when it comes first; an already expired TokenInfo is not stored and the previous entry for the key is removed.