Table of Contents

Class SecureCache

Namespace
Arc4u.Blazor.Caching
Assembly
Arc4u.OAuth2.Blazor.dll

Provides a secure cache implementation.

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

Remarks

The values are kept in memory, in the browser session of the application. The expiration arguments (timeout and isSlided) are ignored, and a value added under a key that already exists does not replace the existing one.

Methods

Dispose()

Disposes the cache object. There is nothing to release.

public void Dispose()

GetAsync<TValue>(string, CancellationToken)

Asynchronously gets the value associated with the specified key.

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

Parameters

key string

The key of the value to get.

cancellation CancellationToken

A cancellation token that can be used to cancel the operation.

Returns

Task<TValue>

A task that represents the asynchronous operation. The task result contains the value associated with the specified key.

Type Parameters

TValue

Exceptions

KeyNotFoundException

There is no value for the key.

Get<TValue>(string)

Gets the value associated with the specified key.

public TValue Get<TValue>(string key)

Parameters

key string

The key of the value to get.

Returns

TValue

The value associated with the specified key.

Type Parameters

TValue

Exceptions

KeyNotFoundException

There is no value for the key.

Initialize(string)

Empties the cache. The store name is not used.

public void Initialize(string store)

Parameters

store string

The store name, which is ignored.

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

Asynchronously adds the specified key and value to the cache. The expiration arguments are ignored and nothing is done when the key already exists.

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

Parameters

key string

The key of the element to add.

timeout TimeSpan

The expiration time, which is ignored.

value T

The value of the element to add.

isSlided bool

The sliding expiration flag, which is ignored.

cancellation CancellationToken

A cancellation token that can be used to cancel the operation.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

T

PutAsync<T>(string, T, CancellationToken)

Asynchronously adds the specified key and value to the cache. Nothing is done when the key already exists.

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

Parameters

key string

The key of the element to add.

value T

The value of the element to add.

cancellation CancellationToken

A cancellation token that can be used to cancel the operation.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

T

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

Adds the specified key and value to the cache. The expiration arguments are ignored and nothing is done when the key already exists.

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

Parameters

key string

The key of the element to add.

timeout TimeSpan

The expiration time, which is ignored.

value T

The value of the element to add.

isSlided bool

The sliding expiration flag, which is ignored.

Type Parameters

T

Put<T>(string, T)

Adds the specified key and value to the cache. Nothing is done when the key already exists.

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

Parameters

key string

The key of the element to add.

value T

The value of the element to add.

Type Parameters

T

Remove(string)

Removes the value with the specified key from the cache.

public bool Remove(string key)

Parameters

key string

The key of the element to remove.

Returns

bool

True if the element is successfully found and removed; otherwise, false.

RemoveAsync(string, CancellationToken)

Asynchronously removes the value with the specified key from the cache.

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

Parameters

key string

The key of the element to remove.

cancellation CancellationToken

A cancellation token that can be used to cancel the operation.

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains a boolean indicating whether the element was successfully found and removed.

TryGetValueAsync<TValue>(string, CancellationToken)

Asynchronously tries to get the value associated with the specified key.

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

Parameters

key string

The key of the value to get.

cancellation CancellationToken

A cancellation token that can be used to cancel the operation.

Returns

Task<TValue>

A task that represents the asynchronous operation. The task result contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.

Type Parameters

TValue

TryGetValue<TValue>(string, out TValue?)

Tries to get the value associated with the specified key.

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

Parameters

key string

The key of the value to get.

value TValue

When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter.

Returns

bool

True if the cache contains an element with the specified key; otherwise, false.

Type Parameters

TValue