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, IUnitOfWorkManager)

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

Fields

DefaultCacheOptions

Declaration
protected DistributedCacheEntryOptions DefaultCacheOptions
Field Value
Type Description
DistributedCacheEntryOptions

UowCacheName

Declaration
public const string UowCacheName = null
Field Value
Type Description
System.String

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

UnitOfWorkManager

Declaration
protected IUnitOfWorkManager UnitOfWorkManager { get; }
Property Value
Type Description
IUnitOfWorkManager

Methods

Get(TCacheKey, Nullable<Boolean>, 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, bool considerUow = false)
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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache.

Returns
Type Description
TCacheItem

The cache item, or null.

GetAsync(TCacheKey, Nullable<Boolean>, 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, bool considerUow = false, 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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the 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>, Boolean)

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

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

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

GetManyFallback(TCacheKey[], Nullable<Boolean>, Boolean)

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

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

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

GetOrAdd(TCacheKey, Func<TCacheItem>, Func<DistributedCacheEntryOptions>, Nullable<Boolean>, 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, bool considerUow = false)
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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache.

Returns
Type Description
TCacheItem

The cache item.

GetOrAddAsync(TCacheKey, Func<Task<TCacheItem>>, Func<DistributedCacheEntryOptions>, Nullable<Boolean>, 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, bool considerUow = false, 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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache.

CancellationToken token

The System.Threading.CancellationToken for the task.

Returns
Type Description
Task<TCacheItem>

The cache item.

GetUnitOfWorkCache()

Declaration
protected virtual Dictionary<TCacheKey, UnitOfWorkCacheItem<TCacheItem>> GetUnitOfWorkCache()
Returns
Type Description
Dictionary<TCacheKey, UnitOfWorkCacheItem<TCacheItem>>

GetUnitOfWorkCacheKey()

Declaration
protected virtual string GetUnitOfWorkCacheKey()
Returns
Type Description
System.String

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>)

Refreshes the cache value of the given key, and resets its sliding expiration timeout.

Declaration
public virtual void Refresh(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.

RefreshAsync(TCacheKey, Nullable<Boolean>, CancellationToken)

Refreshes the cache value of the given key, and resets its sliding expiration timeout.

Declaration
public virtual Task RefreshAsync(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

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

Remove(TCacheKey, Nullable<Boolean>, Boolean)

Removes the cache item for given key from cache.

Declaration
public virtual void Remove(TCacheKey key, bool? hideErrors = null, bool considerUow = false)
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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache.

RemoveAsync(TCacheKey, Nullable<Boolean>, Boolean, CancellationToken)

Removes the cache item for given key from cache.

Declaration
public virtual Task RemoveAsync(TCacheKey key, bool? hideErrors = null, bool considerUow = false, 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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the 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.

Set(TCacheKey, TCacheItem, DistributedCacheEntryOptions, Nullable<Boolean>, 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, bool considerUow = false)
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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the cache.

SetAsync(TCacheKey, TCacheItem, DistributedCacheEntryOptions, Nullable<Boolean>, 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, bool considerUow = false, 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.

System.Boolean considerUow

This will store the cache in the current unit of work until the end of the current unit of work does not really affect the 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>, Boolean)

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

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

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

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

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

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

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

ShouldConsiderUow(Boolean)

Declaration
protected virtual bool ShouldConsiderUow(bool considerUow)
Parameters
Type Name Description
System.Boolean considerUow
Returns
Type Description
System.Boolean

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