#### [Abblix\.Oidc\.Server](https://www.abblix.com/en/docs/api/abblix-oidc-server 'index')
### [Abblix\.Oidc\.Server\.Features\.Storages](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages '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\.

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

Inheritance [System\.Object](https://learn.microsoft.com/en-us/dotnet/api/system.object 'System\.Object') → DistributedCacheStorage

Implements [IEntityStorage](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.IEntityStorage 'Abblix\.Oidc\.Server\.Features\.Storages\.IEntityStorage')
### Constructors

## DistributedCacheStorage\(IDistributedCache, IBinarySerializer\) Constructor {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.DistributedCacheStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer)}

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

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

###### `cache` [Microsoft\.Extensions\.Caching\.Distributed\.IDistributedCache](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.caching.distributed.idistributedcache 'Microsoft\.Extensions\.Caching\.Distributed\.IDistributedCache') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.DistributedCacheStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer).cache}

The distributed cache backend used for storing and retrieving data\.

###### `serializer` [IBinarySerializer](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer 'Abblix\.Oidc\.Server\.Common\.Interfaces\.IBinarySerializer') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.DistributedCacheStorage(Microsoft.Extensions.Caching.Distributed.IDistributedCache,Abblix.Oidc.Server.Common.Interfaces.IBinarySerializer).serializer}

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

## DistributedCacheStorage\.GetAsync\<T\>\(string, bool, Nullable\<CancellationToken\>\) Method {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.GetAsync_T_(string,bool,System.Nullable_System.Threading.CancellationToken_)}

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\)](https://learn.microsoft.com/en-us/dotnet/api/abblix.utils.distributedcacheextensions.trygetandremoveasync#abblix-utils-distributedcacheextensions-trygetandremoveasync(microsoft-extensions-caching-distributed-idistributedcache-system-string-system-nullable{system-timespan}-system-threading-cancellationtoken) 'Abblix\.Utils\.DistributedCacheExtensions\.TryGetAndRemoveAsync\(Microsoft\.Extensions\.Caching\.Distributed\.IDistributedCache,System\.String,System\.Nullable\{System\.TimeSpan\},System\.Threading\.CancellationToken\)')\.

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

###### `T` {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.GetAsync_T_(string,bool,System.Nullable_System.Threading.CancellationToken_).T}

The type of the object to retrieve\.
#### Parameters

###### `key` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.GetAsync_T_(string,bool,System.Nullable_System.Threading.CancellationToken_).key}

The key associated with the object to retrieve\.

###### `removeOnRetrieval` [System\.Boolean](https://learn.microsoft.com/en-us/dotnet/api/system.boolean 'System\.Boolean') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.GetAsync_T_(string,bool,System.Nullable_System.Threading.CancellationToken_).removeOnRetrieval}

Whether to remove the object from the cache after retrieval\.

###### `token` [System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.GetAsync_T_(string,bool,System.Nullable_System.Threading.CancellationToken_).token}

An optional cancellation token to cancel the operation\.

Implements [GetAsync&lt;T&gt;\(string, bool, Nullable&lt;CancellationToken&gt;\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.IEntityStorage#Abblix.Oidc.Server.Features.Storages.IEntityStorage.GetAsync_T_(string,bool,System.Nullable_System.Threading.CancellationToken_) 'Abblix\.Oidc\.Server\.Features\.Storages\.IEntityStorage\.GetAsync\<T\>\(string, bool, System\.Nullable\<System\.Threading\.CancellationToken\>\)')

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[T](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.GetAsync_T_(string,bool,System.Nullable_System.Threading.CancellationToken_).T 'Abblix\.Oidc\.Server\.Features\.Storages\.DistributedCacheStorage\.GetAsync\<T\>\(string, bool, System\.Nullable\<System\.Threading\.CancellationToken\>\)\.T')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
A task that completes when the operation finishes\. containing the retrieved object, if found;
            otherwise, null\.

## DistributedCacheStorage\.RemoveAsync\(string, Nullable\<CancellationToken\>\) Method {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.RemoveAsync(string,System.Nullable_System.Threading.CancellationToken_)}

Asynchronously removes an object from the distributed cache\.

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

###### `key` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.RemoveAsync(string,System.Nullable_System.Threading.CancellationToken_).key}

The key of the object to remove\.

###### `token` [System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.RemoveAsync(string,System.Nullable_System.Threading.CancellationToken_).token}

An optional cancellation token to cancel the operation\.

Implements [RemoveAsync\(string, Nullable&lt;CancellationToken&gt;\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.IEntityStorage#Abblix.Oidc.Server.Features.Storages.IEntityStorage.RemoveAsync(string,System.Nullable_System.Threading.CancellationToken_) 'Abblix\.Oidc\.Server\.Features\.Storages\.IEntityStorage\.RemoveAsync\(string, System\.Nullable\<System\.Threading\.CancellationToken\>\)')

#### Returns
[System\.Threading\.Tasks\.Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task '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 {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_)}

Asynchronously stores an object in the distributed cache\.

```csharp
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` {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_).T}

The type of the object to store\.
#### Parameters

###### `key` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_).key}

The key under which the object is stored\.

###### `value` [T](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_).T 'Abblix\.Oidc\.Server\.Features\.Storages\.DistributedCacheStorage\.SetAsync\<T\>\(string, T, Abblix\.Oidc\.Server\.Features\.Storages\.StorageOptions, System\.Nullable\<System\.Threading\.CancellationToken\>\)\.T') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_).value}

The object to store\.

###### `options` [StorageOptions](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.StorageOptions 'Abblix\.Oidc\.Server\.Features\.Storages\.StorageOptions') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_).options}

Configuration options for the cache entry, such as expiration\.

###### `token` [System\.Nullable&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1')[System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 'System\.Nullable\`1') {#Abblix.Oidc.Server.Features.Storages.DistributedCacheStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_).token}

An optional cancellation token to cancel the operation\.

Implements [SetAsync&lt;T&gt;\(string, T, StorageOptions, Nullable&lt;CancellationToken&gt;\)](https://www.abblix.com/en/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.Storages.IEntityStorage#Abblix.Oidc.Server.Features.Storages.IEntityStorage.SetAsync_T_(string,T,Abblix.Oidc.Server.Features.Storages.StorageOptions,System.Nullable_System.Threading.CancellationToken_) 'Abblix\.Oidc\.Server\.Features\.Storages\.IEntityStorage\.SetAsync\<T\>\(string, T, Abblix\.Oidc\.Server\.Features\.Storages\.StorageOptions, System\.Nullable\<System\.Threading\.CancellationToken\>\)')

#### Returns
[System\.Threading\.Tasks\.Task](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task 'System\.Threading\.Tasks\.Task')  
A task that completes when the operation finishes\.
