Show / Hide Table of Contents

Class DistributedCache<TCacheItem, TCacheKey>

Represents a distributed cache of TCacheItem type. Uses a generic cache key type of TCacheKey type.

Inheritance
System.Object
DistributedCache<TCacheItem, TCacheKey>
DistributedCache<TCacheItem>
Implements
IDistributedCache<TCacheItem, TCacheKey>
Namespace: Volo.Abp.Caching
Assembly: Volo.Abp.Caching.dll
Syntax
public class DistributedCache<TCacheItem, TCacheKey> : object, IDistributedCache<TCacheItem, TCacheKey> where TCacheItem : class
Type Parameters
Name Description
TCacheItem

The type of cache item being cached.

TCacheKey

The type of cache key being used.

Constructors

DistributedCache(IOptions<AbpDistributedCacheOptions>, IDistributedCache, ICancellationTokenProvider, IDistributedCacheSerializer, IDistributedCacheKeyNormalizer, IHybridServiceScopeFactory)

Declaration
public DistributedCache(IOptions<AbpDistributedCacheOptions> distributedCacheOption, IDistributedCache cache, ICancellationTokenProvider cancellationTokenProvider, IDistributedCacheSerializer serializer, IDistributedCacheKeyNormalizer keyNormalizer, IHybridServiceScopeFactory serviceScopeFactory)
Parameters
Type Name Description
IOptions<AbpDistributedCacheOptions> distributedCacheOption
Volo.Abp.Caching.IDistributedCache cache
ICancellationTokenProvider cancellationTokenProvider
IDistributedCacheSerializer serializer
IDistributedCacheKeyNormalizer keyNormalizer
IHybridServiceScopeFactory serviceScopeFactory

Fields

DefaultCacheOptions

Declaration
protected DistributedCacheEntryOptions DefaultCacheOptions
Field Value
Type Description
DistributedCacheEntryOptions

Properties

Cache

Declaration
protected IDistributedCache Cache { get; }
Property Value
Type Description
Volo.Abp.Caching.IDistributedCache

CacheName

Declaration
protected string CacheName { get; set; }
Property Value
Type Description
System.String

CancellationTokenProvider

Declaration
protected ICancellationTokenProvider CancellationTokenProvider { get; }
Property Value
Type Description
ICancellationTokenProvider

IgnoreMultiTenancy

Declaration
protected bool IgnoreMultiTenancy { get; set; }
Property Value
Type Description
System.Boolean

KeyNormalizer

Declaration
protected IDistributedCacheKeyNormalizer KeyNormalizer { get; }
Property Value
Type Description
IDistributedCacheKeyNormalizer

Logger

Declaration
public ILogger<DistributedCache<TCacheItem, TCacheKey>> Logger { get; set; }
Property Value
Type Description
ILogger<DistributedCache<TCacheItem, TCacheKey>>

Serializer

Declaration
protected IDistributedCacheSerializer Serializer { get; }
Property Value
Type Description
IDistributedCacheSerializer

ServiceScopeFactory

Declaration
protected IHybridServiceScopeFactory ServiceScopeFactory { get; }
Property Value
Type Description
IHybridServiceScopeFactory

SyncSemaphore

Declaration
protected SemaphoreSlim SyncSemaphore { get; }
Property Value
Type Description
SemaphoreSlim

Methods

Get(TCacheKey, Nullable<Boolean>)

Gets a cache item with the given key. If no cache item is found for the given key then returns null.

Declaration
public virtual TCacheItem Get(TCacheKey key, bool? hideErrors = null)
Parameters
Type Name Description
TCacheKey key

The key of cached item to be retrieved from the cache.

System.Nullable<System.Boolean> hideErrors

Indicates to throw or hide the exceptions for the distributed cache.

Returns
Type Description
TCacheItem

The cache item, or null.

GetAsync(TCacheKey, Nullable<Boolean>, CancellationToken)

Gets a cache item with the given key. If no cache item is found for the given key then returns null.

Declaration
public virtual Task<TCacheItem> GetAsync(TCacheKey key, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
TCacheKey key

The key of cached item to be retrieved from the cache.

System.Nullable<System.Boolean> hideErrors

Indicates to throw or hide the exceptions for the distributed cache.

CancellationToken token

The System.Threading.CancellationToken for the task.

Returns
Type Description
Task<TCacheItem>

The cache item, or null.

GetDefaultCacheEntryOptions()

Declaration
protected virtual DistributedCacheEntryOptions GetDefaultCacheEntryOptions()
Returns
Type Description
DistributedCacheEntryOptions

GetMany(IEnumerable<TCacheKey>, Nullable<Boolean>)

Declaration
public virtual KeyValuePair<TCacheKey, TCacheItem>[] GetMany(IEnumerable<TCacheKey> keys, bool? hideErrors = null)
Parameters
Type Name Description
IEnumerable<TCacheKey> keys
System.Nullable<System.Boolean> hideErrors
Returns
Type Description
KeyValuePair<TCacheKey, TCacheItem>[]

GetManyAsync(IEnumerable<TCacheKey>, Nullable<Boolean>, CancellationToken)

Declaration
public virtual Task<KeyValuePair<TCacheKey, TCacheItem>[]> GetManyAsync(IEnumerable<TCacheKey> keys, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
IEnumerable<TCacheKey> keys
System.Nullable<System.Boolean> hideErrors
CancellationToken token
Returns
Type Description
Task<KeyValuePair<TCacheKey, TCacheItem>[]>

GetManyFallback(TCacheKey[], Nullable<Boolean>)

Declaration
protected virtual KeyValuePair<TCacheKey, TCacheItem>[] GetManyFallback(TCacheKey[] keys, bool? hideErrors = null)
Parameters
Type Name Description
TCacheKey[] keys
System.Nullable<System.Boolean> hideErrors
Returns
Type Description
KeyValuePair<TCacheKey, TCacheItem>[]

GetManyFallbackAsync(TCacheKey[], Nullable<Boolean>, CancellationToken)

Declaration
protected virtual Task<KeyValuePair<TCacheKey, TCacheItem>[]> GetManyFallbackAsync(TCacheKey[] keys, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
TCacheKey[] keys
System.Nullable<System.Boolean> hideErrors
CancellationToken token
Returns
Type Description
Task<KeyValuePair<TCacheKey, TCacheItem>[]>

GetOrAdd(TCacheKey, Func<TCacheItem>, Func<DistributedCacheEntryOptions>, Nullable<Boolean>)

Gets or Adds a cache item with the given key. If no cache item is found for the given key then adds a cache item provided by factory delegate and returns the provided cache item.

Declaration
public virtual TCacheItem GetOrAdd(TCacheKey key, Func<TCacheItem> factory, Func<DistributedCacheEntryOptions> optionsFactory = null, bool? hideErrors = null)
Parameters
Type Name Description
TCacheKey key

The key of cached item to be retrieved from the cache.

Func<TCacheItem> factory

The factory delegate is used to provide the cache item when no cache item is found for the given key.

Func<DistributedCacheEntryOptions> optionsFactory

The cache options for the factory delegate.

System.Nullable<System.Boolean> hideErrors

Indicates to throw or hide the exceptions for the distributed cache.

Returns
Type Description
TCacheItem

The cache item.

GetOrAddAsync(TCacheKey, Func<Task<TCacheItem>>, Func<DistributedCacheEntryOptions>, Nullable<Boolean>, CancellationToken)

Gets or Adds a cache item with the given key. If no cache item is found for the given key then adds a cache item provided by factory delegate and returns the provided cache item.

Declaration
public virtual Task<TCacheItem> GetOrAddAsync(TCacheKey key, Func<Task<TCacheItem>> factory, Func<DistributedCacheEntryOptions> optionsFactory = null, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
TCacheKey key

The key of cached item to be retrieved from the cache.

Func<Task<TCacheItem>> factory

The factory delegate is used to provide the cache item when no cache item is found for the given key.

Func<DistributedCacheEntryOptions> optionsFactory

The cache options for the factory delegate.

System.Nullable<System.Boolean> hideErrors

Indicates to throw or hide the exceptions for the distributed cache.

CancellationToken token

The System.Threading.CancellationToken for the task.

Returns
Type Description
Task<TCacheItem>

The cache item.

HandleException(Exception)

Declaration
protected virtual void HandleException(Exception ex)
Parameters
Type Name Description
Exception ex

HandleExceptionAsync(Exception)

Declaration
protected virtual Task HandleExceptionAsync(Exception ex)
Parameters
Type Name Description
Exception ex
Returns
Type Description
Task

NormalizeKey(TCacheKey)

Declaration
protected virtual string NormalizeKey(TCacheKey key)
Parameters
Type Name Description
TCacheKey key
Returns
Type Description
System.String

Refresh(TCacheKey, Nullable<Boolean>)

Declaration
public virtual void Refresh(TCacheKey key, bool? hideErrors = null)
Parameters
Type Name Description
TCacheKey key
System.Nullable<System.Boolean> hideErrors

RefreshAsync(TCacheKey, Nullable<Boolean>, CancellationToken)

Declaration
public virtual Task RefreshAsync(TCacheKey key, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
TCacheKey key
System.Nullable<System.Boolean> hideErrors
CancellationToken token
Returns
Type Description
Task

Remove(TCacheKey, Nullable<Boolean>)

Declaration
public virtual void Remove(TCacheKey key, bool? hideErrors = null)
Parameters
Type Name Description
TCacheKey key
System.Nullable<System.Boolean> hideErrors

RemoveAsync(TCacheKey, Nullable<Boolean>, CancellationToken)

Declaration
public virtual Task RemoveAsync(TCacheKey key, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
TCacheKey key
System.Nullable<System.Boolean> hideErrors
CancellationToken token
Returns
Type Description
Task

Set(TCacheKey, TCacheItem, DistributedCacheEntryOptions, Nullable<Boolean>)

Sets the cache item value for the provided key.

Declaration
public virtual void Set(TCacheKey key, TCacheItem value, DistributedCacheEntryOptions options = null, bool? hideErrors = null)
Parameters
Type Name Description
TCacheKey key

The key of cached item to be retrieved from the cache.

TCacheItem value

The cache item value to set in the cache.

DistributedCacheEntryOptions options

The cache options for the value.

System.Nullable<System.Boolean> hideErrors

Indicates to throw or hide the exceptions for the distributed cache.

SetAsync(TCacheKey, TCacheItem, DistributedCacheEntryOptions, Nullable<Boolean>, CancellationToken)

Sets the cache item value for the provided key.

Declaration
public virtual Task SetAsync(TCacheKey key, TCacheItem value, DistributedCacheEntryOptions options = null, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
TCacheKey key

The key of cached item to be retrieved from the cache.

TCacheItem value

The cache item value to set in the cache.

DistributedCacheEntryOptions options

The cache options for the value.

System.Nullable<System.Boolean> hideErrors

Indicates to throw or hide the exceptions for the distributed cache.

CancellationToken token

The System.Threading.CancellationToken for the task.

Returns
Type Description
Task

The System.Threading.Tasks.Task indicating that the operation is asynchronous.

SetDefaultOptions()

Declaration
protected virtual void SetDefaultOptions()

SetMany(IEnumerable<KeyValuePair<TCacheKey, TCacheItem>>, DistributedCacheEntryOptions, Nullable<Boolean>)

Declaration
public void SetMany(IEnumerable<KeyValuePair<TCacheKey, TCacheItem>> items, DistributedCacheEntryOptions options = null, bool? hideErrors = null)
Parameters
Type Name Description
IEnumerable<KeyValuePair<TCacheKey, TCacheItem>> items
DistributedCacheEntryOptions options
System.Nullable<System.Boolean> hideErrors

SetManyAsync(IEnumerable<KeyValuePair<TCacheKey, TCacheItem>>, DistributedCacheEntryOptions, Nullable<Boolean>, CancellationToken)

Declaration
public virtual Task SetManyAsync(IEnumerable<KeyValuePair<TCacheKey, TCacheItem>> items, DistributedCacheEntryOptions options = null, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
IEnumerable<KeyValuePair<TCacheKey, TCacheItem>> items
DistributedCacheEntryOptions options
System.Nullable<System.Boolean> hideErrors
CancellationToken token
Returns
Type Description
Task

SetManyFallback(KeyValuePair<TCacheKey, TCacheItem>[], DistributedCacheEntryOptions, Nullable<Boolean>)

Declaration
protected virtual void SetManyFallback(KeyValuePair<TCacheKey, TCacheItem>[] items, DistributedCacheEntryOptions options = null, bool? hideErrors = null)
Parameters
Type Name Description
KeyValuePair<TCacheKey, TCacheItem>[] items
DistributedCacheEntryOptions options
System.Nullable<System.Boolean> hideErrors

SetManyFallbackAsync(KeyValuePair<TCacheKey, TCacheItem>[], DistributedCacheEntryOptions, Nullable<Boolean>, CancellationToken)

Declaration
protected virtual Task SetManyFallbackAsync(KeyValuePair<TCacheKey, TCacheItem>[] items, DistributedCacheEntryOptions options = null, bool? hideErrors = null, CancellationToken token = null)
Parameters
Type Name Description
KeyValuePair<TCacheKey, TCacheItem>[] items
DistributedCacheEntryOptions options
System.Nullable<System.Boolean> hideErrors
CancellationToken token
Returns
Type Description
Task

ToCacheItem(Byte[])

Declaration
protected virtual TCacheItem ToCacheItem(byte[] bytes)
Parameters
Type Name Description
System.Byte[] bytes
Returns
Type Description
TCacheItem

ToCacheItems(Byte[][], TCacheKey[])

Declaration
protected virtual KeyValuePair<TCacheKey, TCacheItem>[] ToCacheItems(byte[][] itemBytes, TCacheKey[] itemKeys)
Parameters
Type Name Description
System.Byte[][] itemBytes
TCacheKey[] itemKeys
Returns
Type Description
KeyValuePair<TCacheKey, TCacheItem>[]

ToRawCacheItems(KeyValuePair<TCacheKey, TCacheItem>[])

Declaration
protected virtual KeyValuePair<string, byte[]>[] ToRawCacheItems(KeyValuePair<TCacheKey, TCacheItem>[] items)
Parameters
Type Name Description
KeyValuePair<TCacheKey, TCacheItem>[] items
Returns
Type Description
KeyValuePair<System.String, System.Byte[]>[]

Implements

IDistributedCache<TCacheItem, TCacheKey>

Extension Methods

AbpObjectExtensions.As<T>(Object)
AbpObjectExtensions.To<T>(Object)
AbpObjectExtensions.IsIn<T>(T, T[])
AbpObjectExtensions.If<T>(T, Boolean, Func<T, T>)
AbpObjectExtensions.If<T>(T, Boolean, Action<T>)
LockExtensions.Locking(Object, Action)
LockExtensions.Locking<T>(T, Action<T>)
LockExtensions.Locking<TResult>(Object, Func<TResult>)
LockExtensions.Locking<T, TResult>(T, Func<T, TResult>)
Back to top Powered by Volosoft