Skip to main content

DistributedCacheStorage Class

Abblix.Oidc.Server

Abblix.Oidc.Server.Features.Storages

DistributedCacheStorage Class

Provides a general-purpose distributed caching mechanism with serialization support, enabling the storage and retrieval of serialized objects.

public sealed class DistributedCacheStorage : Abblix.Oidc.Server.Features.Storages.IEntityStorage

Inheritance System.Object → DistributedCacheStorage

Implements IEntityStorage

Constructors

DistributedCacheStorage(IDistributedCache, IBinarySerializer) Constructor

Provides a general-purpose distributed caching mechanism with serialization support, enabling the storage and retrieval of serialized objects.

public DistributedCacheStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache cache, Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer serializer);

Parameters

cache Microsoft.Extensions.Caching.Distributed.IDistributedCache

The distributed cache backend used for storing and retrieving data.

serializer IBinarySerializer

The serializer used for converting objects to and from binary format.

Methods

DistributedCacheStorage.GetAsync<T>(string, bool, Nullable<CancellationToken>) Method

Asynchronously retrieves an object from the distributed cache. When removeOnRetrieval is true, uses atomic get-and-remove operation via Abblix.Utils.DistributedCacheExtensions.TryGetAndRemoveAsync(Microsoft.Extensions.Caching.Distributed.IDistributedCache,System.String,System.Nullable{System.TimeSpan},System.Threading.CancellationToken).

public System.Threading.Tasks.Task<T?> GetAsync<T>(string key, bool removeOnRetrieval, System.Nullable<System.Threading.CancellationToken> token=null);

Type parameters

T

The type of the object to retrieve.

Parameters

key System.String

The key associated with the object to retrieve.

removeOnRetrieval System.Boolean

Whether to remove the object from the cache after retrieval.

token System.Nullable<System.Threading.CancellationToken>

An optional cancellation token to cancel the operation.

Implements GetAsync<T>(string, bool, Nullable<CancellationToken>)

Returns

System.Threading.Tasks.Task<T>
A task that completes when the operation finishes. containing the retrieved object, if found; otherwise, null.

DistributedCacheStorage.RemoveAsync(string, Nullable<CancellationToken>) Method

Asynchronously removes an object from the distributed cache.

public System.Threading.Tasks.Task RemoveAsync(string key, System.Nullable<System.Threading.CancellationToken> token=null);

Parameters

key System.String

The key of the object to remove.

token System.Nullable<System.Threading.CancellationToken>

An optional cancellation token to cancel the operation.

Implements RemoveAsync(string, Nullable<CancellationToken>)

Returns

System.Threading.Tasks.Task
A task that completes when the removal has been issued to the cache.

DistributedCacheStorage.SetAsync<T>(string, T, StorageOptions, Nullable<CancellationToken>) Method

Asynchronously stores an object in the distributed cache.

public System.Threading.Tasks.Task SetAsync<T>(string key, T value, Abblix.Oidc.Server.Features.Storages.StorageOptions options, System.Nullable<System.Threading.CancellationToken> token=null);

Type parameters

T

The type of the object to store.

Parameters

key System.String

The key under which the object is stored.

value T

The object to store.

options StorageOptions

Configuration options for the cache entry, such as expiration.

token System.Nullable<System.Threading.CancellationToken>

An optional cancellation token to cancel the operation.

Implements SetAsync<T>(string, T, StorageOptions, Nullable<CancellationToken>)

Returns

System.Threading.Tasks.Task
A task that completes when the operation finishes.