Table of Contents

Class ServerPrincipalCache

Namespace
Arc4u.OAuth2.Security.Principal
Assembly
Arc4u.OAuth2.dll

An ISecureCache that delegates to the token cache configured through TokenCacheOptions (see ICacheHelper).

[Export(typeof(ISecureCache))]
[Shared]
public class ServerPrincipalCache : ISecureCache, ICache, IDisposable
Inheritance
ServerPrincipalCache
Implements
Inherited Members

Constructors

ServerPrincipalCache(ICacheHelper)

Initializes a new instance of the ServerPrincipalCache class.

public ServerPrincipalCache(ICacheHelper cacheHelper)

Parameters

cacheHelper ICacheHelper

The helper giving access to the token cache.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

Releases the reference to the underlying cache.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true when called from Dispose().

GetAsync<TValue>(string, CancellationToken)

Asynchronously gets the value stored for the key.

public Task<TValue?> GetAsync<TValue>(string key, CancellationToken cancellation = default)

Parameters

key string

The key used to identify the value in the cache.

cancellation CancellationToken

A CancellationToken to cancel the operation.

Returns

Task<TValue>

The value, or the default of TValue when no value exists for the key.

Type Parameters

TValue

The type of the value.

Exceptions

CacheNotInitializedException

The cache is not initialized.

DataCacheException

The cache engine or the deserialization failed; the original exception is the inner exception.

Get<TValue>(string)

Gets the value stored for the key.

public TValue? Get<TValue>(string key)

Parameters

key string

The key used to identify the value in the cache.

Returns

TValue

The value, or the default of TValue when no value exists for the key.

Type Parameters

TValue

The type of the value.

Exceptions

CacheNotInitializedException

The cache is not initialized.

DataCacheException

The cache engine or the deserialization failed; the original exception is the inner exception.

Initialize(string)

Initializes the cache. This must be called once every time a cache is created.

public void Initialize(string store)

Parameters

store string

The name of the cache, as declared in the configuration; it identifies the options and the store used.

PutAsync<T>(string, TimeSpan, T, bool, CancellationToken)

Asynchronously adds or replaces a value in the cache with an expiration.

public Task PutAsync<T>(string key, TimeSpan timeout, T value, bool isSlided = false, CancellationToken cancellation = default)

Parameters

key string

The key used to identify the value in the cache.

timeout TimeSpan

The period of validity of the value. When it expires, the value is removed from the cache.

value T

The value to save; it cannot be null. The default of a value type (0, false) is saved.

isSlided bool

true to restart the period each time the value is read (sliding expiration); false for an absolute expiration. Not every cache supports a sliding expiration (the Dapr cache throws NotSupportedException).

cancellation CancellationToken

A CancellationToken to cancel the operation.

Returns

Task

A task that completes when the value is saved.

Type Parameters

T

The type of the value.

Exceptions

ArgumentNullException

value is null.

CacheNotInitializedException

The cache is not initialized.

NotSupportedException

isSlided is true and the cache does not support it.

PutAsync<T>(string, T, CancellationToken)

Asynchronously adds or replaces a value in the cache, without a specific expiration.

public Task PutAsync<T>(string key, T value, CancellationToken cancellation = default)

Parameters

key string

The key used to identify the value in the cache.

value T

The value to save; it cannot be null. The default of a value type (0, false) is saved.

cancellation CancellationToken

A CancellationToken to cancel the operation.

Returns

Task

A task that completes when the value is saved.

Type Parameters

T

The type of the value.

Exceptions

ArgumentNullException

value is null.

CacheNotInitializedException

The cache is not initialized.

DataCacheException

The cache engine or the serialization failed (the original exception is the inner exception), or the memory cache is full.

Put<T>(string, TimeSpan, T, bool)

Adds or replaces a value in the cache with an expiration.

public void Put<T>(string key, TimeSpan timeout, T value, bool isSlided = false)

Parameters

key string

The key used to identify the value in the cache.

timeout TimeSpan

The period of validity of the value. When it expires, the value is removed from the cache.

value T

The value to save; it cannot be null. The default of a value type (0, false) is saved.

isSlided bool

true to restart the period each time the value is read (sliding expiration); false for an absolute expiration. Not every cache supports a sliding expiration (the Dapr cache throws NotSupportedException).

Type Parameters

T

The type of the value.

Exceptions

ArgumentNullException

value is null.

CacheNotInitializedException

The cache is not initialized.

NotSupportedException

isSlided is true and the cache does not support it.

Put<T>(string, T)

Adds or replaces a value in the cache, without a specific expiration.

public void Put<T>(string key, T value)

Parameters

key string

The key used to identify the value in the cache.

value T

The value to save; it cannot be null. The default of a value type (0, false) is saved.

Type Parameters

T

The type of the value.

Exceptions

ArgumentNullException

value is null.

CacheNotInitializedException

The cache is not initialized.

DataCacheException

The cache engine or the serialization failed (the original exception is the inner exception), or the memory cache is full.

Remove(string)

Removes the value stored for the key.

public bool Remove(string key)

Parameters

key string

The key used to identify the value in the cache.

Returns

bool

true when the operation succeeded; false when the underlying cache raised an error.

Exceptions

CacheNotInitializedException

The cache is not initialized.

RemoveAsync(string, CancellationToken)

Asynchronously removes the value stored for the key.

public Task<bool> RemoveAsync(string key, CancellationToken cancellation = default)

Parameters

key string

The key used to identify the value in the cache.

cancellation CancellationToken

A CancellationToken to cancel the operation.

Returns

Task<bool>

true when the operation succeeded; false when the underlying cache raised an error.

Exceptions

CacheNotInitializedException

The cache is not initialized.

TryGetValueAsync<TValue>(string, CancellationToken)

Asynchronously tries to get the value stored for the key. Errors raised while reading or deserializing are not thrown.

public Task<TValue?> TryGetValueAsync<TValue>(string key, CancellationToken cancellation = default)

Parameters

key string

The key used to identify the value in the cache.

cancellation CancellationToken

A CancellationToken to cancel the operation.

Returns

Task<TValue>

The value, or the default of TValue when it is not found or could not be read.

Type Parameters

TValue

The type of the value.

Exceptions

CacheNotInitializedException

The cache is not initialized.

TryGetValue<TValue>(string, out TValue?)

Tries to get the value stored for the key. Errors raised while reading or deserializing are not thrown.

public bool TryGetValue<TValue>(string key, out TValue? value)

Parameters

key string

The key used to identify the value in the cache.

value TValue

The value, or the default of TValue when it is not found or could not be read.

Returns

bool

true when the key exists and a non-null value was read; otherwise false.

Type Parameters

TValue

The type of the value.

Exceptions

CacheNotInitializedException

The cache is not initialized.