Table of Contents

Class CacheContext

Namespace
Arc4u.Caching
Assembly
Arc4u.Caching.dll

CacheContext is a helper class allowing to easily access the caches defined in the caching configuration section.

[Export(typeof(ICacheContext))]
[Shared]
public class CacheContext : ICacheContext
Inheritance
CacheContext
Implements
Inherited Members

Constructors

CacheContext(IConfiguration, ILogger<CacheContext>, IServiceProvider)

Initialise the cache following the caching config section. The caches flagged IsAutoStart are created and initialized immediately; the others are registered and initialized on their first use.

public CacheContext(IConfiguration configuration, ILogger<CacheContext> logger, IServiceProvider dependency)

Parameters

configuration IConfiguration

The configuration that contains the Caching section.

logger ILogger<CacheContext>

The logger.

dependency IServiceProvider

The service provider used to resolve the ICache implementations by kind.

CacheContext(IConfiguration, ILogger<CacheContext>, IServiceProvider, string)

Initialise the cache following the given caching config section. The caches flagged IsAutoStart are created and initialized immediately; the others are registered and initialized on their first use.

public CacheContext(IConfiguration configuration, ILogger<CacheContext> logger, IServiceProvider dependency, string sectionName)

Parameters

configuration IConfiguration

The configuration that contains the caching section.

logger ILogger<CacheContext>

The logger.

dependency IServiceProvider

The service provider used to resolve the ICache implementations by kind.

sectionName string

The name of the caching configuration section.

Fields

Dapr

The kind of cache implemented by the Dapr state store cache (Arc4u.Caching.Dapr).

public const string Dapr = "Dapr"

Field Value

string

DefaultSectionName

The default name of the caching configuration section.

public const string DefaultSectionName = "Caching"

Field Value

string

Memory

The kind of cache implemented by the memory cache (Arc4u.Caching.Memory).

public const string Memory = "Memory"

Field Value

string

Redis

The kind of cache implemented by the Redis cache (Arc4u.Caching.Redis).

public const string Redis = "Redis"

Field Value

string

RedisSentinel

The kind of cache implemented by the Redis Sentinel cache (Arc4u.Caching.Redis).

public const string RedisSentinel = "RedisSentinel"

Field Value

string

Sql

The kind of cache implemented by the SQL Server cache (Arc4u.Caching.Sql).

public const string Sql = "Sql"

Field Value

string

Properties

Default

Accessor to retrieve the default cache defined in the caching config section of the config file.

public ICache Default { get; }

Property Value

ICache

Exceptions

InvalidOperationException

No cache is configured with the default name.

this[string]

Indexer to retrieve the ICache implementation based on the caching config section. The key is the cache name.

public ICache this[string cacheName] { get; }

Parameters

cacheName string

The name of the cache, as declared in the configuration.

Property Value

ICache

An ICache implementation defined in the cache config section.

Exceptions

InvalidOperationException

Throw the exception when the cache name does not exist in the caching config section.

Methods

Exist(string)

Determines whether a cache with this name is declared in the configuration, whether it is already initialized or not.

public bool Exist(string cacheName)

Parameters

cacheName string

The name of the cache.

Returns

bool

true when the cache exists; otherwise false.

NormalizeKind(string)

Returns the canonical kind (Memory, Redis, RedisSentinel, Sql or Dapr) matching kind case-insensitively. Any other kind is returned unchanged, so custom kinds are resolved with the exact key they are registered with.

public static string NormalizeKind(string kind)

Parameters

kind string

The kind read from the configuration.

Returns

string

The key used to resolve the keyed ICache service.