Class ApplicationCache
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
loggerILoggerThe logger.
resolverTokenCacheResolverResolves 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
keystringThe key of the token.
optionsNamestringThe name of the TokenCacheOptions to use, or null for the default ones.
cancellationTokenCancellationTokenA 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
keystringThe unique key.
optionsNamestringThe name of the TokenCacheOptions to use, or null for the default ones.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- ValueTask<T>
The value, or the default of
Twhen there is none.
Type Parameters
TThe 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
keystringThe unique key.
dataTThe value to store. A null value is ignored by some implementations.
optionsNamestringThe name of the TokenCacheOptions to use, or null for the default ones.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- ValueTask
A task that completes when the value is stored.
Type Parameters
TThe 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.