Class CacheContext
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
configurationIConfigurationThe configuration that contains the
Cachingsection.loggerILogger<CacheContext>The logger.
dependencyIServiceProviderThe 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
configurationIConfigurationThe configuration that contains the caching section.
loggerILogger<CacheContext>The logger.
dependencyIServiceProviderThe service provider used to resolve the ICache implementations by kind.
sectionNamestringThe 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
DefaultSectionName
The default name of the caching configuration section.
public const string DefaultSectionName = "Caching"
Field Value
Memory
The kind of cache implemented by the memory cache (Arc4u.Caching.Memory).
public const string Memory = "Memory"
Field Value
Redis
The kind of cache implemented by the Redis cache (Arc4u.Caching.Redis).
public const string Redis = "Redis"
Field Value
RedisSentinel
The kind of cache implemented by the Redis Sentinel cache (Arc4u.Caching.Redis).
public const string RedisSentinel = "RedisSentinel"
Field Value
Sql
The kind of cache implemented by the SQL Server cache (Arc4u.Caching.Sql).
public const string Sql = "Sql"
Field Value
Properties
Default
Accessor to retrieve the default cache defined in the caching config section of the config file.
public ICache Default { get; }
Property Value
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
cacheNamestringThe name of the cache, as declared in the configuration.
Property Value
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
cacheNamestringThe name of the cache.
Returns
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
kindstringThe kind read from the configuration.