![]() |
Sphyrnidae Common Library
2.0.1
Shared Utilities/Library
|
Caching allows you to quickly retrieve saved data/objects instead of always having to lookup data. Data/objects from cache are NOT real-time objects, so please be aware of this if you are using frequently-changing data. Caching is most useful for slowly changing data (or best for static-data), as this avoids a typically to a database or other data source.
The ICache interface has the following methods:
Interface: ICache
Mock: CacheNone
Implementations:
Wrapper: Caching - currently contains no additional capability, you can generally just directly call the interface methods.
If an object has been updated after it was placed in cache, the cached instance will no longer be accurate. In some business scenarios, that is acceptable. However, you should utilize the following techniques to help ensure the cached object is accurate:
For the CacheLocalAndDistributed implementation, the Remove method will not only remove it from the local cache that happens to be running, but also distributed cache, AND will send out a SignalR request to other servers to also clear their local cache. The API default setup for SignalR is to subscribe and handle these caching removal requests based on the Environmental variable: URL.Hub.Cache
Class | Key | Seconds | Description |
---|---|---|---|
AuthenticationMiddleware | $"ApiAuth_{app.Name}_{application}_{token}" | 30 | Specifies if an application is authenticated for API<=>API communication |
EncryptionKeyManager | EncryptionKeys | Default | Retrieves information related to encryption keys |
IFeatureToggleSettings | FeatureToggleSettings | 600 | Stores feature toggle settings for the application |
IUserPreferenceSettings | UserPreferenceSettings | 1200 | Stores user preferences for a given user |
IVariableSettings | VariableSettings | Minute | Stores variables/configurations for the application |
ILoggerConfiguration | Logging_Enabled_Types | 1200 | Which types of loggers are enabled |
ILoggerConfiguration | Logging_Includes | 1200 | Optional attributes to log for a given type |
ILoggerConfiguration | Logging_Enabled_Loggers | 1200 | Which loggers are enabled |
ILoggerConfiguration | $"Logging_Enabled_{name}_Types" | 1200 | For a given logger, what types are enabled for that logger |
ILoggerConfiguration | Logging_HideKeys | 1200 | Listing of logging keys where the values will be obfuscated in the log |
// Injected: ICache cache const string Key = "MyKey"; cache.Options.Seconds = CacheOptions.Day; cache.Options.Priority = CacheItemPriority.NeverRemove; if (!cache.Get(Key, out string foo)) cache.Set(Key, "MyValue"); cache.Options.Seconds = CacheOptions.Hour; cache.Options.Priority = CacheItemPriority.Low; foo = cache.Get(Key, () => "MyValue"); foo = await Caching.GetAsync(cache, key, async () => await MyAsyncMethod()); var ex = Caching.Remove(cache, key);