Show / Hide Table of Contents

Class CacheManager

Utility class for dealing with caches.

Inheritance
object
CacheManager
Implements
ICacheManager
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Data.Cache
Assembly: SoDataBase.BusinessLogic.dll
Syntax
public class CacheManager : ICacheManager

Constructors

CacheManager(DatabaseInstanceContainer, IOptions<OnlineConfiguration>, ILogger<CacheManager>)

Utility class for dealing with caches.

Declaration
public CacheManager(DatabaseInstanceContainer cacheContainer, IOptions<ConfigFile.OnlineConfiguration> onlineConfiguration, ILogger<CacheManager> logger)
Parameters
Type Name Description
DatabaseInstanceContainer cacheContainer
IOptions<ConfigFile.OnlineConfiguration> onlineConfiguration
ILogger<CacheManager> logger

Properties

CacheCheckTimer

Timer to synchronize caches with CacheInvalidationTableInfo.

Declaration
public Timer CacheCheckTimer { get; }
Property Value
Type Description
Timer

ForceRefreshTimer

Timer to force cache refresh.

Declaration
public Timer ForceRefreshTimer { get; }
Property Value
Type Description
Timer

Methods

AddAutoDisableTables(string[])

Enter scope - disable auto-update of caches depending on any of the given tables by incrementing the disable-count

Declaration
public void AddAutoDisableTables(string[] namesToDisable)
Parameters
Type Name Description
string[] namesToDisable

Flush(params CacheBaseV2[])

Removes the cache instance from the system so it'll be queued for GC, next time we request the cache it will be recreated.

Declaration
public void Flush(params CacheBaseV2[] caches)
Parameters
Type Name Description
CacheBaseV2[] caches

Flush<T>()

Removes the cache instance from the system so it'll be queued for GC, next time we request the cache it will be recreated.

Declaration
public void Flush<T>() where T : CacheBaseV2
Type Parameters
Name Description
T

GetAllCacheNames()

Returns names of all caches, not just the tables

Declaration
public IEnumerable<string> GetAllCacheNames()
Returns
Type Description
IEnumerable<string>

GetAllCachesByTableNames()

Get a lookup that leads from table name to caches dependent on that table

Declaration
public ILookup<string, CacheBaseV2> GetAllCachesByTableNames()
Returns
Type Description
ILookup<string, CacheBaseV2>
Remarks

fetch all the caches we currently have in-memory in the current Context caches are indexed preferably by their dependent-table names; or if there are none (what??), by the cache class name

GetAllCachesInContext()

Utility class for dealing with caches.

Declaration
public IEnumerable<CacheBaseV2> GetAllCachesInContext()
Returns
Type Description
IEnumerable<CacheBaseV2>

GetOrCreateAsync<T>(CancellationToken)

This method is declare sync, but returns a ValueTaskT. It contains a private async method that does any needed async/await work, but this happens rarely and we avoid having the whole async state machine (and async "contagion" to outside clients.

Declaration
[CreateSyncVersion(OmitNullableDirective = true)]
public ValueTask<T> GetOrCreateAsync<T>(CancellationToken cancellationToken = default) where T : CacheBaseV2
Parameters
Type Name Description
CancellationToken cancellationToken
Returns
Type Description
ValueTask<T>
Type Parameters
Name Description
T

GetOrCreate<T>()

This method is declare sync, but returns a ValueTaskT. It contains a private async method that does any needed async/await work, but this happens rarely and we avoid having the whole async state machine (and async "contagion" to outside clients.

Declaration
public T GetOrCreate<T>() where T : CacheBaseV2
Returns
Type Description
T
Type Parameters
Name Description
T

InstanceDispose()

Utility class for dealing with caches.

Declaration
public void InstanceDispose()

IsAutoUpdateDisabled(string)

Determine if automatic updates are disabled for a particular table (not a particular cache!)

Declaration
public bool IsAutoUpdateDisabled(string tableName)
Parameters
Type Name Description
string tableName
Returns
Type Description
bool

RegisterAsync(CacheBaseV2, CancellationToken)

Register a cache within the caching system. This is typically called by the CacheBaseV2 cache base class.

Declaration
public Task RegisterAsync(CacheBaseV2 cache, CancellationToken cancellationToken = default)
Parameters
Type Name Description
CacheBaseV2 cache

Cache to register.

CancellationToken cancellationToken
Returns
Type Description
Task
Remarks

An intended side effect is to get the primary key of the corresponding row in the CacheInvalidation table. Missing rows are not a problem; they will cause the row to be inserted the first time we want to register an invalidation (due to a SoftTrigger notification)

RegisterAsync(string[], CancellationToken)

Utility class for dealing with caches.

Declaration
public Task RegisterAsync(string[] cachedTables, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string[] cachedTables
CancellationToken cancellationToken
Returns
Type Description
Task

RegisterCacheInvalidationAsync(string, CancellationToken)

Register (by writing to the CacheInvalidation table) that a cached table has been changed

Declaration
public Task RegisterCacheInvalidationAsync(string tableName, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string tableName
CancellationToken cancellationToken
Returns
Type Description
Task
Remarks

When a cache is instantiated, it registers with us and we retrieve its CacheInvalidation key(s). Therefore, if _generationCache does not have it, it's probable but not certain that we need to insert a row. Conversely, if we do have it then it's very probable that such a row exists and should be updated.
We might be wrong in both cases due to external changes to the database, so the strategy is try one/try the other in any case; what varies is what we try first.

RemoveAutoDisableTablesAsync(string[], CancellationToken)

Exit scope - decrement disable-count of each given table; update each dependent cache once; wait for cache update to complete

Declaration
public Task RemoveAutoDisableTablesAsync(string[] namesToReenable, CancellationToken cancellationToken = default)
Parameters
Type Name Description
string[] namesToReenable
CancellationToken cancellationToken
Returns
Type Description
Task

Unregister(CacheBaseV2)

Unregisters a cache from the cache system. Next time you get a cache it will be a new instance with fresh data.

Declaration
public void Unregister(CacheBaseV2 cache)
Parameters
Type Name Description
CacheBaseV2 cache

Cache to unregister.

Implements

ICacheManager

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top