Class ConfigurableMigrationCacheBase<TKey, TValue>
IMigrationCache<TKey, TValue> implementation that allows for configurable memory caching.
Inheritance
Namespace: Tableau.Migration.Engine.Caching
Assembly: Tableau.Migration.dll
Syntax
public abstract class ConfigurableMigrationCacheBase<TKey, TValue> : IMigrationCache<TKey, TValue>, IDisposable where TKey : notnull where TValue : class
Type Parameters
Name | Description |
---|---|
TKey | |
TValue |
Constructors
ConfigurableMigrationCacheBase(IConfigReader, string)
Creates a new ConfigurableMigrationCacheBase<TKey, TValue> object.
Declaration
public ConfigurableMigrationCacheBase(IConfigReader config, string cacheKey)
Parameters
Type | Name | Description |
---|---|---|
IConfigReader | config | The configuration reader. |
string | cacheKey | The unique key for the cache to use for configuration. |
Properties
DefaultMemoryCacheOptions
Gets the default memory cache options to merge with user options for this cache.
Declaration
protected virtual MemoryCacheOptions DefaultMemoryCacheOptions { get; }
Property Value
Type | Description |
---|---|
MemoryCacheOptions |
MemoryCache
Gets the inner memory cache.
Declaration
protected MemoryCache MemoryCache { get; }
Property Value
Type | Description |
---|---|
MemoryCache |
WriteSemaphore
Gets a semaphore to lock for thread safety when writing.
Declaration
protected SemaphoreSlim WriteSemaphore { get; }
Property Value
Type | Description |
---|---|
SemaphoreSlim |
Methods
Add(TKey, IResult<TValue>)
Adds a find result to the cache for later use.
Declaration
protected virtual void Add(TKey key, IResult<TValue> findResult)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The cache item key. |
IResult<TValue> | findResult | The result of the find operation. |
Add(TKey, TValue)
Adds a value to the cache.
Declaration
public void Add(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to add the value for. |
TValue | value | The value to add. |
BuildCacheOptions(IConfigReader, string)
Builds the memory cache options to use based on current configuration.
Declaration
protected virtual MemoryCacheOptions BuildCacheOptions(IConfigReader configReader, string cacheKey)
Parameters
Type | Name | Description |
---|---|---|
IConfigReader | configReader | The configuration reader. |
string | cacheKey | The unique key for the cache to use for configuration. |
Returns
Type | Description |
---|---|
MemoryCacheOptions | The MemoryCacheOptions to use. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Disposes of the cache.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Whether or not to dispose managed resources. |
FindCacheMissAsync(TKey, CancellationToken)
Finds the value to cache for a given cache key.
Declaration
protected abstract Task<IResult<TValue>> FindCacheMissAsync(TKey key, CancellationToken cancel)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to find the value for. |
CancellationToken | cancel | The cancellation token to obey. |
Returns
Type | Description |
---|---|
Task<IResult<TValue>> | The result of the find operation with the value to cache. |
GetOrAddAsync(TKey, CancellationToken)
Gets or retrieves a value from the cache.
Declaration
public Task<IResult<TValue>> GetOrAddAsync(TKey key, CancellationToken cancel)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to get or retrive a value for. |
CancellationToken | cancel | The cancellation token to obey. |
Returns
Type | Description |
---|---|
Task<IResult<TValue>> | A result with the cached or retrieved value, or any errors that occurred. |
MergeOptions(CacheOptions, MemoryCacheOptions)
Builds a MemoryCacheOptions object from user configuration options and fallback default values specific to this cache.
Declaration
protected MemoryCacheOptions MergeOptions(CacheOptions options, MemoryCacheOptions defaultOptions)
Parameters
Type | Name | Description |
---|---|---|
CacheOptions | options | The user supplied configuration options. |
MemoryCacheOptions | defaultOptions | The fallback default values specific to this cache. |
Returns
Type | Description |
---|---|
MemoryCacheOptions | The merged MemoryCacheOptions. |